LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-15-2012, 04:22 PM   #1
paperboy21
LQ Newbie
 
Registered: Sep 2006
Posts: 1

Rep: Reputation: 0
ensuring one script finishes before another begins


I have a script (a.sh) from which I run 6 other scripts (a1.sh, a2.sh ... a6.sh). I have each of the other scripts set up to run in the background (i.e. they start with 'nohup' and end with an ampersand) so that they run in parallel, rather than running one after another.

### a.sh
nohup a1.sh &
nohup a2.sh &
nohup a3.sh &
nohup a4.sh &
nohup a5.sh &
nohup a6.sh &
### end of a.sh

I now find that script a3.sh needs to wait to start until script a1.sh has completed. I know that I can create a new script (for example, b.sh) which runs a1.sh & a3.sh, and then I would replace these in a.sh with b.sh.

### a.sh
nohup a2.sh &
nohup a4.sh &
nohup a5.sh &
nohup a6.sh &
nohup b.sh
### end of a.sh

### b.sh
a1.sh
a3.sh
### end of b.sh

But I am wondering if there might be a way to accomplish this without needing another script? Something along the lines of:
### a.sh
nohup begin a1.sh a3.sh end &
nohup a2.sh &
nohup a4.sh &
nohup a5.sh &
nohup a6.sh &
### end of a.sh

Tim
 
Old 08-15-2012, 05:56 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
Create a variable with the exit code of the a1.sh process then put your a3.sh into a if or while loop that waits until the exit code on a1.sh comes back as 0 and then it will execute.
 
Old 08-15-2012, 06:00 PM   #3
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 90
Forgive my simple mind but how about appending script a3.sh to a1.sh ? I don't mean to sound sarcastic. I just want to know.
 
Old 08-15-2012, 06:03 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
Sharpy has a point, that would be really simple and sounds like it would accomplish what you are looking to do. Unless you want to be able to call upon the scripts separately at some point in the future.
 
  


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
Program/Manager for ensuring ISO integrity loadedmind Linux - Newbie 4 10-26-2011 10:55 AM
If a script is already running 3 times wait till one finishes before starting another Techno Guy Linux - Newbie 3 04-21-2009 08:58 PM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 11:15 AM
Best way of ensuring ME? MadCactus Programming 0 03-22-2004 06:55 AM
ensuring security sundarrnathan Linux - Security 1 06-03-2003 12:12 PM


All times are GMT -5. The time now is 10:15 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