2

With BASH_ENV assigned in /etc/environment I noticed that it doesn't affect cron jobs.

I figured out that having SHELL=/bin/bash in a users' crontab does the trick! Yes! If I simply add (to the crontab):

SHELL=/bin/bash

... it works. I can go in as root and do a simple:

sed -i 1iSHELL=/bin/bash /var/spool/cron/*

However, I'd like to have this setting global (or the default).

Is it possible to set default cron SHELL as bash?

I've already tried the following, none of which did the trick:

  • Adding the line in /etc/crontab effects only the /etc/crontab itself not all users
  • Adding to /etc/sysconfig/crond and restart the cron
  • Adding to /etc/environment and cron restart
  • Added session required pam_env.so readenv=1 to /etc/pam.d/crond and restart cron
  • Added line to /etc/default/cron and another restart

How to set default cron SHELL as bash?

2 Answers 2

3

There is no way to set a global default shell for cron jobs.

1

An alternative is that if you are running shell scripts from crontab, then you can put this at the top of the script.

#!/bin/bash -l

This will make it act like a login shell.

1
  • Neat suggestion/workaround, but this would require me now to change all scripts (and I also wonder if there's any downside with the -l and if/why not to do it) . I know I can just add to all crontabs like this: sed -i 1iSHELL=/bin/bash /var/spool/cron/* as root, but I'm hoping for something more neat.
    – lzc
    Sep 11, 2016 at 17:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .