0

in the following bash script , we want to run in parallel several scripts on remote machines

ssh $server_a  /tmp/activate_nodes.bash &
ssh $server_b  /tmp/activate_services.bash &
ssh $server_c  /tmp/activate_components.bash &
ssh $server_d  /tmp/activate_nfs.bash &
.
.
.

not sure about to put the "&" on the end of the script or some other approach ?

Note the target is to run all 25 scripts on 25 diff machines , so all runing of the scripts will be in few second , while scripts proccess on remote machine will still run until end

jessica
  • 2,426
  • 24
  • 66
  • Seems a fair enough approach to me - what is your concern? If you put a `wait` at the end of the script it will wait for all the background tasks to end before terminating the script - otherwise the background tasks might get terminated. – code_fodder May 05 '20 at 21:21
  • my concern is that this steps are simple , and maybe I missed something – jessica May 05 '20 at 21:24
  • oh...lol... then its just simple : ) ... remember the wait at the end though - it will be useful : ) – code_fodder May 05 '20 at 21:25
  • *"The target is to run all 25 scripts on 25 diff machines"*... do you mean you want to start 625 processes altogether? – Mark Setchell May 06 '20 at 17:54

1 Answers1

1

Running these in parallel is fine, except for the interleaved output. To save output for later analysis, you can also "tee" the logs for later inspection:

#!/usr/bin/env bash
ssh $server_a  /tmp/activate_nodes.bash      2>&1 | tee ${server_a}_$$.log &
ssh $server_b  /tmp/activate_services.bash   2>&1 | tee ${server_b}_$$.log &
ssh $server_c  /tmp/activate_components.bash 2>&1 | tee ${server_c}_$$.log &
ssh $server_d  /tmp/activate_nfs.bash        2>&1 | tee ${server_d}_$$.log &
wait
Eric Bolinger
  • 2,722
  • 1
  • 13
  • 22