`sbatch --export` flag not working?

I’ve been attempting to use the --export flag with sbatch to specify per-run environment variables for individual scripts. The function, however, does not seem to be working as it is specified in the SLURM manual for that command.

A minimal example (ran on debug-cpu on Bamboo) is:

script.sh

#!/bin/bash
echo ${A}
echo ${B}

I then, in a terminal with A and B unset, run the following command per the man page:

$ sbatch script.sh --export=A=1,B=2

The expected output is that the file slurm-XXXX.out should contain 1 and 2, but instead the file is empty with no contents.

I have found that running the following command instead will work:

$ export A=1
$ sbatch ./script.sh --export=A=1

but trying to change the value in the --export flag from 1 to another value will retain the original exported value of 1.

The command should work as specified in my first example according to the documentation, allowing me to bind a variable using the export flag only. Am I missing something, or is this a bug?

Dear @Berk.Gercek

The issue here is the argument order: you are specifying the flag --export as argument for your script script.sh which is not what you want. You need to do something like the following:

$ sbatch --export=A=1,B=2 script.sh 

By the way, are you sure you need to that? By default all the users’s env var are propagated. If you specify a variable to export using --export then no other variables are exported.

Hey Yann,

Thank you for the response! I was planning on using the env variables to specify certain parameters to the job script that change between simultaneously submitted jobs. I.e SUBJECT=“A” for one and SUBJECT=“B” for another. It seemed like an easy way to approach the problem, though it seems to be difficult in practice.

In the example you provided the issue is that B is still not passed on to the job script environment. A is successfully propagated but B is empty when echoed. Do you have an idea of why that might be?

Berk

Then, no need to use the export flag. As I said all then env variables are propagated by default. See the example below.

(baobab)-[sagon@login1 ~]$ SUBJECT=A sbatch --wrap "srun env | grep SUBJECT"
Submitted batch job 14275216
(baobab)-[sagon@login1 ~]$ cat slurm-14275216.out
SUBJECT=A

The previous solution I wrote is working too, A and B are correctly exported.

(baobab)-[sagon@login1 ~]$ sbatch --export=A=1,B=2 --wrap "srun /usr/bin/env | grep -e 'B=' -e 'A='"
Submitted batch job 14275228
(baobab)-[sagon@login1 ~]$ cat slurm-14275228.out
A=1
B=2
SLURM_EXPORT_ENV=A=1,B=2

But better avoid to use export flag as it removes other important env variables.

I’ll find a workaround, probably using an env file defining job constants! Thanks.