This question already has an answer here:

I want to execute a process on multiple servers. I am using the following wrapper script. The script moves to servers one at a time. I would like to change it so it can execute on multiple servers. Is there way to do it?

for ip in $(<ALL_SERVERS_IP); do
    # Tell the remote server to start bash, but since its
    # standard input is not a TTY it will start bash in
    # noninteractive mode.
    ssh -q "$ip" bash <<-'EOF'
        printf "%s\n" ================== "$(hostname) ::: Current date : $(date)" \

marked as duplicate by terdon Aug 22 '14 at 11:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


I know some tools for that, but the easiest is Fabric. Take a look and tell me what do you think.

  • All anwsers are useful but I can choose one solution. Thanks! – user67186 Aug 22 '14 at 13:18
  • You're welcome man. I'm glad to help. – Willian Paixao Aug 22 '14 at 20:17

Yes. Try pdsh, which will execute a command on multiple remote hosts simultaneously. Your task could be written like so:

pdsh -w ssh:$(echo $(<ALL_SERVERS) | sed -e 's/ /,/g') 'printf "%s\n" ...'

Sounds like you're looking for GNU Parallel. That's pretty much exactly what it was written for. In your case, you would do:

parallel ./remote --sshloginfile ALL_SERVERS_IP

The above assumes that ALL_SERVERS_IP is a text file with one IP or hostname per line. If they can have different logins, make the list like so:

  • I checked on the central server and couldn't find parallel on it. – user67186 Aug 21 '14 at 17:53
  • @user67186 you only need to install it on your machine, the one you will launch the job from. – terdon Aug 21 '14 at 17:55
  • Use a bash function to give the 'printf/hostname' stuff to run. Then use --env to export that function to the remote server: parallel --env myfunc --slf ALL_SERVERS_IP --nonall myfunc – Ole Tange Aug 22 '14 at 7:08
  • @terdon How do you have to install parallel? Can't find anything useful. – Jenson Jan 27 '16 at 7:34
  • @Jenson see the link in my answer. Most Linux distributions (probably all) will have it in their repositories as parallel. For others, the link provides download packages. – terdon Jan 27 '16 at 10:32

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