Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parameter for shell scripts that is started with qsub

how can I parametrize a shell script that is executed on a grid (started with qsub) ? I have a shell script, where I use getopts to read the parameters.

When I start (qsub script.sh -r firstparam -s secondparam ..) this working script with qsub I receive error messages,

qsub: invalid option -- s

qsub: illegal -r value

as qsub thinks the parameter are for itself. Yet I have not found any solution.

Thanks

like image 319
Martin Avatar asked Aug 17 '10 15:08

Martin


People also ask

What is qsub command?

The qsub command is used to submit jobs to the queue. job, as previously mentioned, is a program or task that may be assigned to run on a cluster system. qsub command is itself simple, however, it to actually run your desired program may be a bit tricky. is because qsub, when used as designed, will only run scripts.

What do shell scripts start with?

Scripts start with a bash bang. This is the first line of the script. Shebang tells the shell to execute it via bash shell. Shebang is simply an absolute path to the bash interpreter.

What is $1 and $2 in shell script?

$0 is the name of the script itself (script.sh) $1 is the first argument (filename1) $2 is the second argument (dir1) $9 is the ninth argument.

What does $() mean in shell script?

$() – the command substitution. ${} – the parameter substitution/variable expansion.


Video Answer


2 Answers

Using the qsub -v option is the proper way:

qsub -v par_name=par_value[,par_name=par_value...] script.sh 

par_name can be used as variable in the shell script.

like image 179
volks Avatar answered Sep 25 '22 07:09

volks


In addition to volk's answer, in order to reference the variables in the list (designated by -v) you simply use the name you define in your call. So, say you made a call to qsub as follows

qsub -v foo='qux' myRunScript.sh

Then myRunScript.sh could look something like this:

#!/bin/bash #PBS -l nodes=1:ppn=16,walltime=0:00:59 #PBS -l mem=62000mb #PBS -m abe  bar=${foo} echo "${bar}" 

Where the output would be

qux 

Hope this helps!

like image 42
jhrf Avatar answered Sep 25 '22 07:09

jhrf