LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-07-2009, 11:42 AM   #1
hawk__0
Member
 
Registered: Nov 2008
Posts: 105

Rep: Reputation: 15
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!
 
Old 10-07-2009, 12:21 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Start each script with an & at the end of the command and then use the wait command.
 
Old 10-07-2009, 01:53 PM   #3
hawk__0
Member
 
Registered: Nov 2008
Posts: 105

Original Poster
Rep: Reputation: 15
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/

Last edited by hawk__0; 10-07-2009 at 01:59 PM.
 
Old 10-07-2009, 02:02 PM   #4
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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
 
Old 10-07-2009, 02:04 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by hawk__0 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Patterns and string processing in shell scripts LXer Syndicated Linux News 0 12-27-2008 12:30 PM
i am running 2 scripts in background if 1 exits with error the other should also exit pradyumna_reddy Programming 2 11-24-2008 02:42 PM
running 2 scripts in background ,if any 1 exits with error the other 1 also exit pradyumna_reddy Linux - General 2 11-20-2008 02:54 PM
form processing scripts help? tuxfood Programming 1 05-11-2004 07:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration