LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Scripts + Background Processing (https://www.linuxquestions.org/questions/linux-software-2/scripts-background-processing-760335/)

hawk__0 10-07-2009 10:42 AM

Scripts + Background Processing
 
Let's say I wanted to have 1 script run 3 scripts:

SCRIPT:
/script1.sh
/script2.sh
/script3.sh
echo "" | mutt -s "scripts all completed!" me@me.com

Is there any way to make it so that I can run all 3 scripts simultaneously, therefore utilizing this computers 4 cores? The catch is that I'd want each script to be fully completed before the email is sent!

catkin 10-07-2009 11:21 AM

Start each script with an & at the end of the command and then use the wait command.

hawk__0 10-07-2009 12:53 PM

I read the description of the wait command. What is a jobspec?

If I ran each command in the background (with &, as you said), and then just use "wait" after them all, will it wait for each process executed by the script to finish? That's what I think I gathered from that description...

EDIT:
I found my answer here, thanks for your help!
http://www.lamolabs.org/blog/1724/on...-wait-command/

forrestt 10-07-2009 01:02 PM

You'll want something like:
Code:

/script1.sh &
/script2.sh &
/script3.sh &
wait > /dev/null 2>&1
echo "" | mutt -s "scripts all completed!" me@me.com

HTH

Forrest

catkin 10-07-2009 01:04 PM

Quote:

Originally Posted by hawk__0 (Post 3711258)
I read the description of the wait command. What is a jobspec?

If I ran each command in the background (with &, as you said), and then just use "wait" after them all, will it wait for each process executed by the script to finish? That's what I think I gathered from that description...

"jobspec" is explained here, immediately above the link given in the previous post, but "wait" with no jobspecs waits for them all so it's academic what jobspecs are (but good to be curious :)). You could test it by writing a script that waits for a random time (not too long!) and echo a "finished!" message to stdout before they exit and background that script several times then issue the wait command.


All times are GMT -5. The time now is 01:38 AM.