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

4
  • 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. Commented May 5, 2020 at 21:21
  • my concern is that this steps are simple , and maybe I missed something Commented May 5, 2020 at 21:24
  • oh...lol... then its just simple : ) ... remember the wait at the end though - it will be useful : ) Commented May 5, 2020 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? Commented May 6, 2020 at 17:54

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

I would add 2>&1 before the pipe to catch the error messages too.
Thanks Jetchisel! You should feel free to edit answers (treating SO as a WIKI). Edits are reviewed as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.