To get Slurm job environment variables, you have several options depending on your needs:
You can print all environment variables inside your Slurm job script using:
bash#!/bin/bash #SBATCH --job-name=my_job #SBATCH --output=output.log # Print all environment variables env
or
bashprintenv
This will output all environment variables, including those set by Slurm.
Slurm sets several environment variables for your job. You can access them directly in your script or after the job completes:
bashecho $SLURM_JOB_ID echo $SLURM_JOB_NAME echo $SLURM_NODELIST echo $SLURM_NTASKS
Common Slurm environment variables
If you want to pass specific environment variables to your job, use the --export option:
bashsbatch --export=ALL,MY_VAR=value my_script.sh
or export only certain variables:
bashsbatch --export=MY_VAR1,MY_VAR2=value my_script.sh
After submitting your job, you can check the environment variables set for a specific job using:
bashscontrol show job <job_id> | grep Environment
or
bashsacct -j <job_id> --format=JobID,JobName,Environment
If you suspect environment issues, you can run a simple bash job with -s to source your environment:
bashsbatch -s -o debug.log ./my_script.sh