Is it possible to retrieve Slurm job environment variables?
Mar 29, 11:52pm

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:


1. Using scontrol

You can use the scontrol command to inspect the environment variables of a running or completed Slurm job:

bash
scontrol 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:

bash
scontrol show job <job_id> | grep Environment

2. Using srun with --export

If you want to pass environment variables to a Slurm job, you can use the --export option with srun or sbatch:

bash
srun --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:

bash
printenv

or

bash
env

inside your job script.


3. Using sacct

For completed jobs, you can use sacct to see job details, though it may not always show environment variables directly:

bash
sacct -j <job_id> --format=JobID,JobName,Env

4. Using sbatch with Environment Variables

If 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"

5. Using scontrol to View Environment at Runtime

If you want to check the environment variables of a running job, you can use:

bash
scontrol show job <job_id> | grep -i env

6. Using srun to View Environment

If you want to see the environment variables of a running job, you can use:

bash
srun --jobid=<job_id> env

Mar 29, 11:52pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.