LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-02-2009, 11:21 AM   #1
Mike_V
Member
 
Registered: Apr 2009
Location: Boston MA
Distribution: CentOS 6.2 x86_64 GNU/Linux
Posts: 59

Rep: Reputation: 19
How to start script_3 after script2a and script2b (that run parallel) are finished?


Hi there,
I have a problem for which I really like your input.
I have two shell scripts (script_2a.sh and script_2b.sh) that are started by single script: script_1.sh.

Script _1.sh simply looks something like this:

Code:
<send the following file to a batch cluster computer> script_2a.sh
<send the following file to a batch cluster computer> script_2b.sh
(I send 2a and 2b off to a cluster computer that can run them in parallel, each script takes between 3 and 6 hours to run, I don’t know before hand which one finishes first)

THE PROBLEM:
When both 2a and 2b are done I automatically would like to start running script_3.sh


I’M THINKING THE SOLUTION MIGHT LOOK LIKE THIS:
1.
I could add a line to both 2a and 2b that produces:
/tmp/script_2a_done.dat
/tmp/script_2b_done.dat

2.
I can have script_1.sh (after it has started 2a and 2b) check whether /tmp/script_2a_done.dat and /tmp/script_2b_done.dat have finished after which it starts script_3.sh.


PRACTICAL QUESTIONS:
1.
Does anybody know how I can make a script that can tell if /tmp/script_2a_done.dat AND /tmp/script_2b_done.dat have been written, so I can tell it to start script_3.sh?

2.
Would anyone recommend a different solution?


Thanks a lot!

Mike

Last edited by Mike_V; 10-02-2009 at 11:44 AM.
 
Old 10-02-2009, 11:46 AM   #2
reickler
LQ Newbie
 
Registered: Sep 2009
Posts: 29

Rep: Reputation: 20
There's a "wait" function in bash that's probably what you're looking for. If you specify it with no arguments, it waits until all backgrounded processes have exited before moving on.

Your script would look something like this:

Code:
script1.sh &
script2.sh &

wait
echo "Both scripts have finished"

You can also pass a PID to "wait" (I believe), so you try something like this if you're worried about the possibility of there being other processes in the pipeline:

Code:
script1.sh &
SCRIPT1_PID=$!

script2.sh &
SCRIPT2_PID=$!

wait $SCRIPT1_PID
wait $SCRIPT2_PID

echo "Both scripts have finished"
 
Old 10-02-2009, 12:46 PM   #3
Mike_V
Member
 
Registered: Apr 2009
Location: Boston MA
Distribution: CentOS 6.2 x86_64 GNU/Linux
Posts: 59

Original Poster
Rep: Reputation: 19
Thanks reickler. You suggestion did the trick. I've used the second option to be sure and it works perfectly!
 
  


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
Scripting: audio playback script - how to run two tasks in parallel? klss Linux - Software 5 01-16-2009 02:17 AM
Start one command after another has finished snowman81 Programming 6 12-18-2007 04:03 AM
LXer: Run Parallel Commands in a Cluster Using SSH on UNIX LXer Syndicated Linux News 0 09-12-2006 01:54 PM
Getting an application to run at start up dgermann Ubuntu 10 08-28-2006 10:32 PM
run something on start k3v0 Linux - General 4 09-16-2002 09:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:37 AM.

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