Execute a command on multiple servers
It’s both amazing and informative to watch those with more skill than you, especially when you can look through logs to see what they did. The latest nugget of awesome I learned reboots a series of apache instances on separate servers.
for i in `seq 1 10` do ssh instance$i rcapache2 restart; done
It basically says “connect to instance1, instance2 and so on and restart the apache server on each”. This approach could easily be modified for more complex tasks. That it’s done on one line is what catches my attention. Prior to seeing this done, I would have SSHed into each server by hand.
Brad Beattie on May 1st, 2009
This would seem to apply as well.
for i in `echo serverA serverB serverC`; do ssh $i ls /home/; done;