Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run three shell script simultaneously

Tags:

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.

like image 236
arsenal Avatar asked Oct 16 '12 04:10

arsenal


People also ask

How do I run multiple shell scripts at the same time?

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.

How do I run multiple scripts in Linux?

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.

How do I run a parallel command in Unix?

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.

How do I run multiple jobs in Unix?

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.


1 Answers

you want this?

$ sh -x script1.sh & sh -x script2.sh & sh -x script3.sh & 

Update explanation :

  • Run each script in background mode so that next command is run without waiting for current command to complete.
  • '&' 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.
like image 187
Rohan Avatar answered Sep 19 '22 17:09

Rohan