#PBS -v MY_VAR gives "cannot send environment with the job" error

Hi all, RHEL7, pbs 19.1.3

test.pbs

#!/bin/bash
#PBS -v MY_VAR
#PBS -J 1-12

echo $MY_VAR
echo ${PBS_ARRAY_INDEX}
echo "running on $(hostname)"

which I’m executing like this, gives:

for MY_VAR in green yellow blue red; do qsub test.pbs; done
qsub: cannot send environment with the job
qsub: cannot send environment with the job
qsub: cannot send environment with the job
qsub: cannot send environment with the job

It does work with

for MY_VAR in green yellow blue red; do qsub -V test.pbs; done

So long as I comment out
# PBS -v MY_VAR

Both the manual and man page suggest that -v in the script should work. What am I doing wrong?

My mistake! When I suggested “it did work” what I meant was “the jobs were submitted successfully”.

The output looks like this in every file:

[user@host ~]$ cat test.pbs.o313985.12

12
running on k180

so the MY_VAR isn’t getting passed through. I must have done something wrong?

Please try this :
for MY_VAR in green yellow blue red; do qsub -v var_$MY_VAR=$MY_VAR test.pbs; done

Check the Varible_List of each of the job using qstat -fx < jobid >

1 Like

I wont lie, that’s not obvious. And it doesn’t solve the problem of either there is a bug or the documentation is wrong wrt #PBS -v MY_VAR and qsub -V? Unless what I’m missing is that it needs to be #PBS -v var=$MY_VAR ?

Could you please check man page for qsub

You need to export MY_VAR in the environment from which qsub is being invoked.

To slightly rephrase what @scc said. There are “shell variables” and “environment variables”. shell variabels are only visible to the current bash shelll process… not do it’s child processes (in this instance the qsub command). When you “export” a variable the shell will include the variable (and it’s value) in the environment of any child processes. To show this isn’t just a qsub thing… here’s an example using the “env” command (which print out any environment variables it inherits from the shell:

[arwild1@hplcva01 ~]$ # look ma, no output
[arwild1@hplcva01 ~]$ for MY_VAR in green yellow blue red; do env |egrep MY_VAR; done
[arwild1@hplcva01 ~]$ # now with output
[arwild1@hplcva01 ~]$ export MY_VAR;  for MY_VAR in green yellow blue red; do env |egrep MY_VAR; done
MY_VAR=green
MY_VAR=yellow
MY_VAR=blue
MY_VAR=red
1 Like