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:
#!/bin/bash #SBATCH --job-name=my_job #SBATCH --output=output.log # Print all environment variables env
or
printenv
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:
echo $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:
--export
sbatch --export=ALL,MY_VAR=value my_script.sh
or export only certain variables:
sbatch --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:
scontrol show job <job_id> | grep Environment
sacct -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:
bash
-s
sbatch -s -o debug.log ./my_script.sh
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.
Vibe can make mistakes. Check answers. Learn more