I have three shell script which I am running as below-
sh -x script1.sh sh -x script2.sh sh -x script3.sh
So each script is executed sequentially one at a time after previous one finished executing.
Problem Statement:-
Is there any way I can execute all the three above scripts at same time from a single window? I just want to execute script1, script2, script3 at the same time. If you think of some CRON JOB scheduling script1 at 3 AM, script2 at 3AM, script3 at 3AM
(all three scripts at the same time, simultaneously). That's what I need, I need to execute all the three scripts simultaneously.
The command to do this is CTRL-B :setw synchronize-panes on. Now you can run scriptName $fruit and view the output on all panes at the same time.
The bg and fg Commands. A handy Linux command for running two scripts simultaneously would be the bg command. Using the bg command, we can resume and control how jobs are run in our terminal. We can set a script to run in the background while running a new script in the foreground.
By default, the command is run sequentially at each computer, but you can specify to run the commands in parallel using background rshells by prefixing the command with certain prefix sequences. If the rshell is run in the background, then each command puts the output in a buffer file at its remote computer.
Running Multiple Commands as a Single Job We can start multiple commands as a single job through three steps: Combining the commands – We can use “;“, “&&“, or “||“ to concatenate our commands, depending on the requirement of conditional logic, for example: cmd1; cmd2 && cmd3 || cmd4.
you want this?
$ sh -x script1.sh & sh -x script2.sh & sh -x script3.sh &
Update explanation :
'&'
makes the scripts run in background so that prompt does not wait for it to complete'&'
also can be used to chain commands on one line similar to running commands one by one on command line.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With