Include Bash Script Arguments When Submitting via Bsub

Include Bash Script Arguments When Submitting via Bsub

I have the following shell script.

#!/bin/bash --login

#BSUB -q q_ab_mpc_work
#BSUB -J psipred
#BSUB -W 01:00
#BSUB -n 64
#BSUB -o psipred.out
#BSUB -e psipred.err
module load compiler/gnu-4.8.0
module load R/3.0.1
export OMP_NUM_THREADS=4

code=${HOME}/Phd/script_dev/rfpipeline.sh
MYPATH=$HOME/Phd/script_dev/
cd ${MYPATH}
${code} myfile.txt

in which I can use bsub to submit program to cluster:

bsub < myprogram.sh

however I change the last line in my program to:

${code} $1

where I use a command line argument to specify the file, how can I pass this to bsub?

I have tried:

bsub < myprogram.sh myfile.text

however bsub will not accept myfile.text as a bash parameter.

I have also tried

bsub <<< myprogram.sh myfile.text
./myprogram.sh myfile.text | bsub
bsub "sh ./myprogram.sh myfile.text"

what do I need to do?

4

2 Answers

Can I answer my own question?

It seems that I can use sed to modify the file on the fly. My original file is now:

#!/bin/bash --login

#BSUB -q q_ab_mpc_work
#BSUB -J psipred
#BSUB -W 01:00
#BSUB -n 64
#BSUB -o psipred.out
#BSUB -e psipred.err
module load compiler/gnu-4.8.0
module load R/3.0.1
export OMP_NUM_THREADS=4

code=${HOME}/Phd/script_dev/rfpipeline.sh
MYPATH=$HOME/Phd/script_dev/
cd ${MYPATH}
${code} myfile

and I wrote a bash script, sender.sh to both modify the variable myfile with a command line argument, and send the modified file off to bsub:

#!/bin/bash
sed "s/myfile/$1/g" < myprogram.sh | bsub

being careful to use double quotes so that bash does not read $ literally. I then simply run ./sender.sh jobfile.txt which works!

Hope this helps anybody.

This answer should resolve your problem:

Just pass the script with arguments at the end of the bsub command.

Ex. example.sh

#!/bin/bash export input=${1} echo "arg input: ${input}"

bsub command:

bsub [bsub args] "path/to/example.sh arg1"

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.