Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

migrated from stackoverflow.com Nov 27 '12 at 8:09

This question came from our site for professional and enthusiast programmers.

1 Answer

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
done

Hope that helps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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