Skip to content

Instantly share code, notes, and snippets.

@markuman
Last active July 15, 2017 00:42
Show Gist options
  • Save markuman/c76ce806e0af813d3bf513e71640fdbe to your computer and use it in GitHub Desktop.
Save markuman/c76ce806e0af813d3bf513e71640fdbe to your computer and use it in GitHub Desktop.
parallel ssh with gnu parallel
#!/bin/bash
#this requires a ~/.ssh/config with your hosts
#and a /tmp/hostlist.csv with one hostname (must match to ~/.ssh/config/) per line
# 32 parallel threads
threads=32
function remote_execute () {
echo $1
ssh -n $1 "sh -c \"$CMD\""
}
export -f remote_execute
if (("$#" == 1)); then
export CMD=$1
cat /tmp/hostlist.csv | parallel --no-notice -j "$threads" remote_execute '{}'
else
echo 'usage: '
echo ' ./remote_exec.sh "git clone https://github.com/reconquest/orgalorg"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment