|
|
|
|
|
by ktopaz
2426 days ago
|
|
Years ago I wrote this tiny script: <run-on-all.sh> #!/bin/bash
clusterfile=$1
cmd="source /etc/profile; $2"
ssh='ssh -n -A -o BatchMode=yes -o ConnectTimeout=10 -o LogLevel=quiet'
#add "-o ConnectTimeout=x" for timing out the ssh connection after x seconds
#redircting stdin for ssh command to /dev/null (using switch "-n" for ssh) since otherwise ssh command breaks bash's "while" loop
#reference: http://www.unix.com/shell-programming-scripting/38060-ssh-break-while-loop.html
echo
while read line;
do
echo "@==============@ running on $line @==============@"
echo
echo
$ssh $line "$cmd"
echo
echo
done < $clusterfile
echo
echo
echo "==============> FINISHED RUNNING for $clusterfile <=============="
All one needs to do is call it like so:
./run-on-all.sh /path/to/cluster/file/list-of-servers-here.txt "sleep 60; reboot" |
|
ansible ad-hoc commands do almost exactly what you do but in a more scalable fashion
https://docs.ansible.com/ansible/latest/user_guide/intro_adh...