Question

I would like to pass variables to a perl script by using "qsub -v" command. This is the perl script I would run (it's just a test but if it doesn't work I cannot do anything more difficult)

#!/usr/bin/perl
use Getopt::Long;
$result = GetOptions ("i=s" => \$config_file);

open(FILE,">/data/home/FILEout.txt");
open(FILE_CONFIG,"<$config_file");
while(<FILE_CONFIG>){
  print FILE "$config_file\n";
}
close(FILE_CONFIG);
close(FILE);

So, if I would run this script (not through qsub) I would type:

perl Test.pl -i FILE_CONFIG.txt

However I would run this script on a node of a cluster that works with pbs. I have done several attemp like the following one:

qsub -l nodes=node06 -v i=/data/home/FILE_CONFIG.txt Test.pl 

but it doesn't work. Anyone as an idea how I should pass the parameter to my perl script using qsub? Any help would be really appreciated

Doesn't work means that using qsub doesn't print nothing on the output file while using just perl it print the content of the input file in the output file. It looks like it doesn't take nothing in input

Was it helpful?

Solution

Would it be easier for you to submit the job this way:

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

Then, as long as you know that Test.pl is in the path you specify on node06, it should work correctly.

OTHER TIPS

The qsub command does not allow command line arguments to be directly passed to the input script. There are two basic ways around that:

  1. Write a wrapper script that calls your actual script with the appropriate arguments. You can even pass the wrapper script to qsub on the standard input, as shown in dbeer's answer, by specifying the script name in the qsub command as "-" or omitting it entirely.

    Note that, if you do this, any embedded #PBS directives must be specified in the wrapper script, not in the inner script called by the wrapper. Of course, if you're not using that particular feature, then you don't need to worry about it.

  2. Pass the arguments through the environment instead, using the -v switch to qsub. That is, if your qsub command looks like this:

    qsub -l nodes=node06 -v CONFIG=/data/home/FILE_CONFIG.txt Test.pl 
    

    then your Test.pl script can read the configuration file path from $ENV{CONFIG}, like this:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    my $config = $ENV{CONFIG} || 'default_config_file_path.txt';
    open CONFIG, '<', $config  or die "Error opening $config: $!\n";
    
    # ... rest of script here ...
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top