Conditional execution of jobs using PBS or slurm

It is possible to start a job on the condition that another one completes beforehand; this may be necessary for instance if the input to one job is generated by another job. Job dependency is defined in PBS using the -W flag.

To illustrate with an example, suppose you need to start a job using the script after another job finished successfully. Assume the first job is started using script and the command to start the first job


returns the job ID 7777. Then, the command to start the second job is

qsub -W depend=afterok:7777

This job dependency can be further automated (possibly to be included in a bash script) using environment variables:


JOB_ID-2=qsub -W depend=afterok:$JOB_ID_1

Ravindra Shinde
Ravindra Shinde
Research Scientist

I am a theoretical and computational condensed matter physicist and quantum chemist. I am currently working as a researcher at the University of Twente, the Netherlands. I am also the founder of The Science Dev.