Run a Command on Multiple Systems at once using Bash – CentOS/RHEL

Hey there friends,

So there are tons of different methods out there for managing multiple systems. Configuration management, centralized command “senders” and the like (CFEngine, Puppet, Ansible, Chef).

One quick and dirty way you can manage multiple systems without setting up anything fancy or new is just with a one line for loop in bash.

Say you have a list called SERVERLIST with the IPs or hosts of your systems in that file, one system per line. You can run a quick for loop, to check that file and then connect to each of the systems, running whatever command you want.

NOTE: having SSH keys and sudo setup will make this a lot more cool as well:

This command will login to every server listed in SERVERLIST and will check to see if there are any ssl related package updates available.

for i in `cat SERVERLIST`; do echo "SERVER: $i"; ssh -Aqt $i sudo su - -c \'yum check-update \| grep -i ssl\' ;echo " ";done