Batch job script traps for Slurm and PBS
FactVerified 2 Oct 2026Holds anywhere
Fact. A statement and the evidence for it.
Statement#
- Slurm stops reading
#SBATCHlines at the first non-comment command, and PBS does the same. Put variables andmodule loadlines after the directives. - A directive is not shell-expanded:
#SBATCH --nodes=$NODESfails, so a block of shell variables cannot feed directives. - Slurm copies the submitting login environment into the job by default, so a script can work for its author and fail for a reader. Start with
module purgeand load modules by name. - A failed step does not fail the job unless the script uses
#!/bin/bash -e. Without it the job still shows as complete. - PBS starts the job in the home directory, so add
cd "$PBS_O_WORKDIR". - Use
$USERor the submit directory, not hardcoded user paths.
Evidence#
Read from the Slurm docs and HPC site guides; no cluster run. The PBS rows and $FLUX_JOB_ID in the source tutorial were written from memory and are not verified.
Also found by searching
- #SBATCH --nodes=$NODES fails in a job script
- my Slurm job script works for me but fails for a reader
- job shows as complete although a step failed
- PBS job starts in the home directory