Reputation: 15126
I use a bash script which makes an ssh connection to other machines and executes scripts (which are stored on those machine).
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?
Upvotes: 0
Views: 183
Reputation: 2371
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
Upvotes: 1
Reputation: 3420
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.
Upvotes: 1