0

I use a bash script which makes an ssh connection to other machines and executes scripts (which are stored on those machine).

  1. SSH to master to execute script 1
  2. SSH to master to execute script 2
  3. SSH to master to execute script 3
  4. SSH to node1 to execute script 1 etc..

Now my question is: Will the execution of script 2 on the master start before the script 1 (which takes 30 seconds) is finished? Will they run at the same time?

1
  • 1
    Like any other command, ssh runs until it's done, unless you specifically run it in the background. Commented Apr 19, 2016 at 6:46

3 Answers 3

1

This would be dependent on how your bash script on your machine (which does the SSH connection to the servers) and the scripts on those servers works.

For example: The following commands are completely procedural and not parallelized so long as scripts 1, 2, and 3 are procedural as well and do not fork work into the background before exiting (i.e. All work is done when the script exits)

ssh master 'script1' 
ssh master 'script2' 
ssh master 'script3' 

This can be simplified as

ssh master 'script1; script2; script3' 

You could parallelize the work by forking these scripts to the background, thus running scripts 1, 2 and 3 at the same time.

ssh master 'script1 &; script2 &; script3 &' 

Again, just make sure that your scripts don't fork work into the background themselves and exit before the work is done

Sign up to request clarification or add additional context in comments.

Comments

1

I'm just giving here a more detailed answer than @tripleee...

Will execute script2 after the completion of script1:

ssh master script1
ssh master script2

You could do the same in one connection:

ssh master 'script1 ; script2'

If you want them to run at the same time:

ssh master 'script1 &; script2 &'

To cite the manual:

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell.

There are posts (like here and here) on how to run multiples commands in one connection.

Comments

0

It depends. Compare

sleep 10
date

sleep 10 &
date

Comments

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.