3

I want to submit a bash script to my university's Sungrid computing cluster to run an executable in a loop. When I log in to the server, I'm in bash:

$ echo $SHELL
/bin/bash

And I include a bash shebang at the top of the script that I pass to qsub:

$ cat shell_sub
#!/bin/bash
#$ -N bSS_s13
#$ -o logs/bSS_s13.log
#$ -j y
#$ -cwd

echo $SHELL > shell.txt

But when I submit the above script:

qsub shell_sub

It instead executes in csh:

$ cat shell.txt
/bin/csh

How can I force qsub to execute my script with bash instead of csh?

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79

3 Answers3

5

Most likely your queue is configured with shell_start_mode as posix_compliant and the defined shell is listed as /bin/csh (which is the default). To check this:

$ qconf -sq <name-of-queue> | grep shell
shell                 /bin/bash
shell_start_mode      unix_behavior

If you don't know the name of your queue, it's probably all.q.

  • If shell_start_mode is posix_compliant, then the shebang line is ignored and the job (if it's not submitted as binary: -b y) is started with the shell defined by the shell setting.
    • Why? From the man page: "POSIX does not consider first script line comments such a ‘#!/bin/csh’ as being significant. The POSIX standard for batch queuing systems (P1003.2d) therefore requires a compliant queuing system to ignore such lines but to use user specified or configured default command interpreters instead."
  • If shell_start_mode is unix_behavior, then the shebang line is used to determine the shell for the job.

You can ask your administrator to consider changing the queue settings.

kgutwin
  • 867
  • 1
  • 10
  • 15
2

You can set the shell for a submitted job (at least in Torque) using -S.

For example: qsub shell_sub -S /bin/bash

dbeer
  • 6,963
  • 3
  • 31
  • 47
0

Thanks but a different order worked for me:

qsub -S /bin/bash shell_sub

  • Please don't add "thank you" as an answer. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation), you will be able to [vote up questions and answers](https://stackoverflow.com/help/privileges/vote-up) that you found helpful. - [From Review](/review/late-answers/34656977) – Kamikaza Jul 11 '23 at 11:34