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
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.
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.
$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.
$() – the command substitution. ${} – the parameter substitution/variable expansion.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With