Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run a series of jobs submitted to the cluster, one after the other, by suplpying the following .sh script: :


job=`qsub 0`
for i in {1..3}
    job_next=`qsub -hold_jid $job $i`

The first job (before entering the loop) is executed, but the next ones are never started.

I think the script is well written. I change the mode to an executable and run it as

nohup ./ (I think this is necessary?) ... but the rest is never done.

I tried -W before, using -W depend=afterok:$job in place of -hold_jid $job


    job=`qsub 0`
    for i in {1..3}
        job_next=`qsub -W depend=afterok:$job $i`

But it returned unknown option -W.

What could be going wrong? :(

share|improve this question
up vote 1 down vote accepted

The ouput of qsub has the jobid inside a message text. In my case:

$ qsub
Your job 8845476 ("") has been submitted

You should extract the jobid from this message. E.g:

$ jobid=$(qsub | cut -d' ' -f3)
$ echo $jobid

Maybe your qsub version, has a different message, try it out separatly and then put a cut to get the jobid as a string.

share|improve this answer
thank you, @zhen! – Carmen Sandoval May 1 '13 at 23:17

For anyone who stumbles across this years later:

I would use an array job for that to avoid writing a shell script. You need something like $SGE_TASK_ID and need to submit with qsub -t 1-3 -tc 1

This creates an array of 3 jobs, numbered 1, 2 and 3, which run one at a time (-tc 1). You no longer need to worry about hold_jid.

SGE_TASK_ID is where the integer id of the current job is held. This is what you pass to your code (equivalent of i in your loop).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.