Last active
April 20, 2016 12:37
-
-
Save progrium/8232241 to your computer and use it in GitHub Desktop.
bash script for executing a command via ssh in parallel on multiple servers with colored output
This file contains 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 | |
# | |
# Usage: | |
# $ echo "host1 host2 host3" | ./sshmany uname -a | |
# $ cat myservers | ./sshmany echo Hello world | |
# | |
cmd="$@" | |
servers="$(cat)" | |
i=37 | |
for server in $servers; do | |
echo "----> $server" | awk -v i=$i '{print "\033[" i "m" $0 "\033[39m"}' | |
i=$(expr $i - 1) | |
done | |
echo "====> $cmd" | |
i=37 | |
for server in $servers; do | |
ssh $server $cmd | awk -v i=$i '{print " \033[" i "m" $0 "\033[39m"}' & | |
i=$(expr $i - 1) | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment