Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 450
brucezepplin Avatar asked Jul 10 '15 09:07

brucezepplin


1 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.

like image 192
brucezepplin Avatar answered Nov 05 '22 07:11

brucezepplin