Yes, you can retrieve Slurm job environment variables in several ways, depending on your needs and the context of your job. Here’s how you can do it:
scontrolYou can use the scontrol command to inspect the environment variables of a running or completed Slurm job:
bashscontrol show job <job_id> --oneliner
This will output a long line containing all the job details, including the environment variables if they were set.
To specifically see the environment variables, you can use:
bashscontrol show job <job_id> | grep Environment
srun with --exportIf you want to pass environment variables to a Slurm job, you can use the --export option with srun or sbatch:
bashsrun --export=ALL,MY_VAR=value your_command
This will export all current environment variables and also set MY_VAR for the job.
To retrieve the environment variables from within the job, you can use:
bashprintenv
or
bashenv
inside your job script.
sacctFor completed jobs, you can use sacct to see job details, though it may not always show environment variables directly:
bashsacct -j <job_id> --format=JobID,JobName,Env
sbatch with Environment VariablesIf you submit a job using sbatch, you can pass environment variables in the submission script:
bash#!/bin/bash #SBATCH --job-name=my_job #SBATCH --export=ALL,MY_VAR=value echo "MY_VAR is: $MY_VAR"
scontrol to View Environment at RuntimeIf you want to check the environment variables of a running job, you can use:
bashscontrol show job <job_id> | grep -i env
srun to View EnvironmentIf you want to see the environment variables of a running job, you can use:
bashsrun --jobid=<job_id> env