0

Hi would like to pass a parameter to my perl script that should be executed trough qsub. So I run:

qsub -l nodes=node01 -v "i=500" Test.pl

While in Test.pl I try to call i parameter in several way:

use Getopt::Long;
$result = GetOptions ("i" => \$num);
open(FILE,">/data/home/FILEout.txt");
    print FILE "$num\n";             
    print FILE "$ARGV[0]";     
close(FILE);

Unfortunatelly output file of the perl script is always empty.

Do you have any suggestions? Where I'm wrong? Help please

desmo
  • 153
  • 2
  • 11
  • What's the output from this `Test.pl`: `use Data::Dumper; open($FH,">/data/home/FILEout.txt") or die $!; local $Data::Dumper::Terse=1; local $Data::Dumper::Indent=0; print($FH Dumper(\@ARGV), "\n"); print($FH join(',', keys(%ENV)), "\n");`? – ikegami Mar 28 '13 at 12:13
  • @ikegami again I really appreciate your help. The output of your Test.pl is the following: `PBS_NODEFILE,PBS_O_SHELL,PBS_O_SYSTEM,SSH_ASKPASS,PBS_O_WORKDIR,PBS_O_LANG,PBS_O_MAIL,PBS_O_PATH,LESSOPEN,PBS_JOBCOOKIE,PWD,LANG,USER,PBS_O_HOST,G_BROKEN_FILENAMES,LOGNAME,PBS_JOBID,SHLVL,INPUTRC,PATH,PBS_ENVIRONMENT,PBS_O_QUEUE,OMP_NUM_THREADS,PBS_QUEUE,HISTSIZE,PBS_O_HOME,PBS_MOMPORT,HOME,MAIL,PBS_O_LOGNAME,TZ,PBS_NODENUM,PBS_TASKNUM,NCPUS,HOSTNAME,_,LS_COLORS,SHELL,PBS_JOBNAME,PBS_JOBDIR,TMPDIR,ENVIRONMENT` using the command `qsub -l nodes=node01 -v "i=500" Test.pl` – desmo Mar 28 '13 at 13:26
  • Makes no sense potato. Is there an example like `#!/bin/sh if [ "x" == "x$MYVAR" ] ; then echo "Variable is not set" else echo "Variable says: $MYVAR" fi` in your `qsub`'s docs? If so, what happens if you try that (with `-v 'MYVAR=500'`)? And what if you change `$MYVAR` to `$i` (with `-v 'i=500'`)? – ikegami Mar 28 '13 at 20:13

2 Answers2

1

According to all documentation I can find -v sets an environment var, so you'd use $ENV{i} to get 500. (Check your own documentation to confirm.)


If you wanted to actually pass an arg to your script, you could try using

qsub ... Test.pl -i=500

But based on my web search, that might only work for some versions of qsub. Others would require that you make a helper script (say Test.sh)

#!/bin/sh
Test.pl "-i=$i"

along with the command

qsub ... -v 'i=500' Test.sh

If qsub ... Test.pl ...args... is supported and you can change your script, the simplest solution is

qsub ... Test.pl 500

and

my ($i) = @ARGV;
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Thanks for the help. I'm using PBRProfessional 10.4. It doesn't support `qsub ... Test.pl -i=500` and how you suggest -v sets an environment variable. So I changed my script and I add `use Env; print FILE "$ENV{i}";` but nothing changed. Do you know why? Thans again – desmo Mar 28 '13 at 12:03
  • @desmo, No, I only have the documentation to go by, and all docs I found show `-v` setting environment vars. (Note that `use Env;` doesn't do anything useful there.) I did add an alternative solution to my answer (using a helper script), but it also assumes `-v` sets environment vars. – ikegami Mar 28 '13 at 12:08
0

I Finally get the solution that works with PBRProfessional 10.4.

There are two way to solve it:

First one is the following

echo "perl /path/to/Test.pl -i 500" | qsub -l nodes=node06

Second one is two use

qsub -l nodes=node06 -v i=500 Test.pl

and read the parameter in the Test.pl through $ENV{i}

desmo
  • 153
  • 2
  • 11