LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03: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, 04:56 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
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, 05:00 PM   #3
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
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, 05:03 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
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



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 09: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 07:58 PM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 10:15 AM
Best way of ensuring ME? MadCactus Programming 0 03-22-2004 05:55 AM
ensuring security sundarrnathan Linux - Security 1 06-03-2003 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:29 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
Open Source Consulting | Domain Registration