Submitting Jobs
Exercises¶
- Submit with a custom output filename
Write a short job script that runs echo "Hello from $HOSTNAME". Use the --output directive to write output to logs/%x_%j.out (job name + job ID). Remember to create the logs/ directory first.
Hint / Solution
mkdir -p logs
cat > custom_output.sh << 'EOF'
#!/bin/bash
#SBATCH --job-name=custom_out
#SBATCH --output=logs/%x_%j.out
#SBATCH --time=00:05:00
#SBATCH --ntasks=1
#SBATCH --mem=1G
echo "Hello from $HOSTNAME"
EOF
sbatch custom_output.sh
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
- Use --wrap for a one-liner
Submit a quick job using --wrap that prints the current date and the contents of /proc/cpuinfo | head -5. Request 5 minutes and 1G of memory on the command line.
Hint / Solution
Expected output: Validated 2026-04-15 onslurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
- Set up email notifications
Modify a job script (or use command-line flags) to send you an email when the job begins, ends, or fails. Submit it and verify the directives with scontrol show job.
Hint / Solution
sbatch --mail-type=BEGIN,END,FAIL --mail-user=you@example.com --time=00:05:00 --wrap="sleep 30"
# Verify the settings
scontrol show job <jobid> | grep -i mail
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sbatch --mail-type=BEGIN,END,FAIL --mail-user=you@example.com --time=00:05:00 --job-name=val_sj3 --wrap='sleep 30'
Submitted batch job 42
$ scontrol show job 42 | grep -i mail
SubmitLine=sbatch --mail-type=BEGIN,END,FAIL --mail-user=you@example.com --time=00:05:00 --job-name=val_sj3 --wrap=sleep 30
MailUser=you@example.com MailType=BEGIN,END,FAIL
- Pass arguments to a job script
Create a job script called greet.sh that accepts two positional arguments: a name ($1) and a project ($2). Have it print "Hello, [name]! Working on [project]." Submit it with arguments.
Hint / Solution
cat > greet.sh << 'EOF'
#!/bin/bash
#SBATCH --job-name=greet
#SBATCH --output=greet_%j.out
#SBATCH --time=00:05:00
NAME=$1
PROJECT=$2
echo "Hello, $NAME! Working on $PROJECT."
EOF
sbatch greet.sh "Alice" "genome_assembly"
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
- Use --chdir to control the working directory
Create a directory called /tmp/$USER/test_chdir. Submit a job that uses --chdir to set the working directory to that path. Inside the script, run pwd to confirm the job started in the right directory.
Hint / Solution
mkdir -p /tmp/$USER/test_chdir
sbatch --chdir=/tmp/$USER/test_chdir --time=00:05:00 --wrap="pwd; echo 'Working dir test' > chdir_test.txt"
# After the job completes, check:
cat /tmp/$USER/test_chdir/chdir_test.txt
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).