bashshellsshpsthredds

Running several scripts in parallel bash scripts on remote machines


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


Solution

  • 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