Last active
July 15, 2017 00:42
-
-
Save markuman/c76ce806e0af813d3bf513e71640fdbe to your computer and use it in GitHub Desktop.
parallel ssh with gnu parallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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