How to Pass Parameters from QSub to Bash Script?
Asked Answered
R

2

20

I'm having an issue passing variables to a Bash script using QSub.

Assume I have a Bash script named example. The format of example is the following:

#!/bin/bash
# (assume other variables have been set)

echo $1 $2 $3 $4

So, executing "bash example.sh this is a test" on Terminal (I am using Ubuntu 12.04.3 LTS, if that helps) produces the output "this is a test".

However, when I enter "qsub -v this,is,a,test example.sh", I get no output. I checked the output file that QSub produces, but the line "this is a test" is nowhere to be found.

Any help would be appreciated.

Thank you.

Rotation answered 20/9, 2013 at 20:12 Comment(1)
Can you show the script you are submitting to qsub and how it calls the bash script example?Salvadorsalvadore
S
29

Using PBSPro or SGE, arguments can simply be placed after the script name as may seem intuitive.

qsub example.sh hello world

In Torque, command line arguments can be submitted using the -F option. Your example.sh will look something like this:

#!/bin/bash echo "$1 $2"

and your command like so:

qsub -F "hello world" example.sh

Alternatively, environment variables can be set using -v with a comma-separated list of variables.

#!/bin/bash echo "$FOO $BAR"

and your command like so:

qsub -v FOO="hello",BAR="world" example.sh

(This may be better phrased as a comment on @William Hay's answer, but I don't have the reputation to do so.)

Scrivener answered 5/1, 2017 at 2:28 Comment(0)
R
10

Not sure which batch scheduler you are using but on PBSPro or SGE then submitting with qsub example.sh this is a test should do what you want.

The Torque batch scheduler doesn't (AFAIK) allow passing command line arguments to the script this way. You would need to create a script looking something like this.

#!/bin/bash

echo $FOO

Then submit it with a command like:

qsub -v FOO="This is a test" example.sh
Rarefy answered 18/10, 2013 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.