3
votes

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?

2
What is the shell type you get on the cluster? (echo $SHELL) - Finch_Powers
@Finch_Powers It says csh... so my entire post is an XY problem. I'll edit to focus on the actual issue. - ApproachingDarknessFish
Try explicitly executing bash: bash -c "echo $SHELL" - Steve
Call "bash" on the remote machine to gain access to that shell and then it your script should work. - Finch_Powers
@Steve I was hoping to use bash constructs like for loops within the body of my script. With your approach I'd need to write two scripts, one to call bash and set qsub variables, and the other to execute my code. I'd prefer a single-file solution. - ApproachingDarknessFish

2 Answers

4
votes

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.

2
votes

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

For example: qsub shell_sub -S /bin/bash