Search code examples
bashcallqsub

Calling a bash script inside another bash script using qsub


I am trying to run a bash script inside another bash script using qsub (since I need to run the actual problem on a cluster).

Here is a demonstration of this problem. I have two scripts as follows:

Script 1:

#!/bin/bash -f
sh ./script2.sh

Script 2:

#!/bin/bash
echo "It works fine!"

Now if I put these two scripts in a folder and use command sh script1.sh, it will work fine. But if I use qsub command for running it qsub script1.sh it will through an error:

sh: ./script2.sh: No such file or directory

How can I fix it?


Solution

  • To define the working directory path to be used for the job -d option can be used. If it is not specified, the default working directory is the home directory.

    Check your working directory.

    #!/bin/bash -f
    echo "Working directory is $PWD"
    sh ./script2.sh
    

    You can use -d option to fix this.

    qsub -d <working directory> script1.sh