LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to launch two shell scripts at once (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-launch-two-shell-scripts-at-once-493481/)

beeblequix 10-18-2006 07:38 AM

how to launch two shell scripts at once
 
I want to launch two shell scripts at once. The first is a korn shell script, the second a bash script. Originally I considered adding the bash script as a line in the korn script but then it occurred to me that the korn script would wait until the bash script is done before moving on to the next line. The idea is that I want the bash script to take snapshots of what's happening during the first 90 seconds of the korn script.

Would this work?:
me@mysles8server> ./mykornscript & ; ./mybashscript

If I read that right it runs the korn script in bg and the bash script in foreground.

Maybe I wouldn't have to use the '&' symbol and just type them both separated by the semicolon --
./mykornscript;./mybashscript

Maybe I can drop that line separated by a semicolon into a script of its own to keep things easy. Hmmm......I'll test this in a few hours when I get to work and report for any other n00bs like me who may find it useful.

matthewg42 10-18-2006 08:00 AM

Separating commands with a semi-colon is just like pressing return, so this:
Code:

command1 ; command2
...would run command1, wait for it to finish and then run command2, wait for that to finish and then give you your prompt back.

If you want to run command1 and command2 in parallel, you can do it with the &, but you don't need the semi-colon:
Code:

command1 & command2
Which will run command1 in the background, run command2 in the foreground, and give you the prompt back when command2 is complete. note that command1 may terminate before command2, but you'll not get the notification until command2 is complete. It could also keep running after you get the prompt back. To check the status of backgrounded jobs, you can type jobs

You could put them both in the background like this:
Code:

command1 & command2 &
...which will put them both in the background and give you the prompt back straight away. There is a special command called wait which waits until all background processes are complete, and then gives you the prompt back. So this command:

Code:

command1 & command2 & wait
Will launch command1 and command2, and wait until both are complete.

Enjoy


All times are GMT -5. The time now is 12:17 PM.