user8578415
user8578415

Reputation: 421

How to make sbatch job run after a previous one has completed?

I was provided two sbatch scripts to submit and run. The input of the second one is based on the output of the first one. The assignment I need to do this for simply tells us to check on the first one every few hours or so and then to submit the second one after it's finished, but is there a way to automate that so the second one runs right after the first is complete? I've already submitted the first one, and it's currently sitting in the queue.

Upvotes: 12

Views: 7652

Answers (1)

damienfrancois
damienfrancois

Reputation: 59340

The sbatch command has a --dependency option:

-d, --dependency= Defer the start of this job until the specified dependencies have been satisfied completed.

Submit the first one with

JOBID1=$(sbatch --parsable <other_options> <submission_script>)

and the dependent one with

sbatch --dependency=afterok:$JOBID1

This will make sure the second one only starts after, and only if, the first on completes successfully.

Upvotes: 17

Related Questions