user123
user123

Reputation: 17

bash: stop subshell script marked as failed if one step exits with an error

I am running a script through the SLURM job scheduler on HPC.

I am invoking a subshell script through a master script.

The subshell script contains several steps. One step in the script sometimes fails because of the quality of the data; this step is not required for further steps, but if this step fails, my whole subshell script is marked with "failed" Status in the job scheduler. However, I need this subshell script to have a "completed" Status in the Job scheduler as it is dependency in my master script.

I tried setting up

set +e

in my subshell script right before the optional step, but it doesn't seem to work: I still get an exitCode with errors and FAILED status inthe job scheduler.

In short: I need the subshell script to have Status "completed" in the job scheduler, no matter whether one particular step is finished with errors or not. Will appreciate help with this.

Upvotes: 1

Views: 310

Answers (1)

damienfrancois
damienfrancois

Reputation: 59260

For Slurm jobs submitted with sbatch, the job exit code is taken to be the return code of the submission script itself. The return code of a Bash script is that of the last command in the script.

So if you just end your script with exit 0, Slurm should consider it COMPLETED no matter what.

Upvotes: 0

Related Questions