I would like to run one bash shell script on two or more machines simultaneously.Can I run one bash shell script on many machines simultaneously? I place this shell script on centos 5.5 and other machines run this simultaneously.

  • How often does this run? And is it important that they run 'simultaneously', or can they be started a few seconds apart on each machine? – Phil H Nov 27 '12 at 8:11

My best bet would be using ssh. For this you probably need to exchange keys between your master machine (the one hosting the original script) and your slaves (the ones supposed to run the script). I.e. you need to do ssh-keygen on the master and append the contents of ~/.ssh/id_rsa.pub (or id_dsa.pub) on the master to ~/.ssh/authorized_keys on each slave. Then you can run a script sitting on the master on each slave like so:

ssh remote_user@slave_machine 'bash -s' < local_script.sh

(which is stolen from this answer).
If you have a list of slave machines you can repeat this on each like so:

slaves = slaveA slaveB ...
for slave in slaves; do
    ssh remote_user@${slave} 'bash -s' < local_script.sh

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.