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 send the program to the cluster:

bsub < myprogram.sh

      

however I change the last line in my program to:

${code} $1

      

where do i use command line argument to specify the file, how to pass this to bsub?

I tried:

bsub < myprogram.sh myfile.text

      

however bsub will not accept myfile.text

bash as a 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?

+3


source to share


2 answers


This answer should solve your problem:

https://unix.stackexchange.com/questions/144518/pass-argument-to-script-then-redirect-script-as-input-to-bsub

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


source


Can I answer my own question?

It seems I can use sed to modify a 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 change a variable myfile

using a command line argument and send the changed file to bsub:



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

      

be careful to use double quotes so that bash doesn't read $

literally. Then I just run ./sender.sh jobfile.txt

that works!

Hope this helps anyone.

0


source







All Articles