LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-27-2010, 12:58 PM   #1
cliffyao
LQ Newbie
 
Registered: Oct 2009
Posts: 27

Rep: Reputation: 15
how to write a shell script for submitting multiple jobs sequentially


I want to write a shell script for submitting multiple jobs sequentially. For example,

#!/bin/bash
qsub job1.sh

# when job1.sh is done, run the next one

qsub job2.sh

Can anyone tell me how to make the shell script know that job1.sh is done and now I can run job2.sh?

Any help will be appreciated.
 
Old 05-27-2010, 01:03 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Use the qstat command?
 
Old 05-27-2010, 01:16 PM   #3
cliffyao
LQ Newbie
 
Registered: Oct 2009
Posts: 27

Original Poster
Rep: Reputation: 15
hmmm, isn't qstat just for checking jobs status?
 
Old 05-27-2010, 01:34 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by cliffyao View Post
hmmm, isn't qstat just for checking jobs status?
Doesn't the status include whether it is finished? (I don't use it or have it installed)
 
Old 05-27-2010, 02:44 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Depending on the queue system installed on the cluster, you might have the command qwait at your disposal. If not, you can actually use the qstat command as suggested by catkin. First store the Job ID (standard output of the qsub command) in a variable, then use the Job Id as argument to qstat. Usually the exit status is 0 for running or queued jobs, 1 otherwise (the man page of qsub should confirm).

Something (simple) like this should do the trick:
Code:
jobid=$(qsub job1.sh)
while qstat $jobid > /dev/null 2>&1
do
  sleep 300
done
I usually redirect standard output to /dev/null (to avoid the job summary list) together with standard error (to avoid the error message coming out when the job has finished and qstat does not find it anymore). If you want to log anything from you script, better to redirect (append) them to a log file.

Hope this helps.
 
  


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
Shell script to copy database archivelogs sequentially from one directory to another rajeshkumar.dba Programming 3 06-02-2009 08:12 AM
Newbie! How do I get background jobs to execute sequentially? Suncoast Programming 11 05-06-2009 12:31 PM
bash script: run multiple jobs in bg, & kill them separately? mattengland Programming 1 03-26-2006 05:07 PM
ps/jobs in shell script paraiso Linux - Newbie 3 04-22-2005 09:04 AM

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

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