What shell is used by cron?
cron runs shell commands from crontabs.
But having just got caught out by the differences between zsh and bash, I'm now concerned that I don't know which shell cron uses to interpret crontab commands? Obviously the simple case where the cron entry just points to a script file is handled by the #!/path/to/interpreter
on the first line, but what when you have something more complex in cron?
I looked in /etc/cron*
and can't see anything that might allow this to be set or changed?
You can put SHELL=/bin/bash
in your crontab
- you can also point to a .bashrc
using BASH_ENV="/root/.bashrc"
. That should get you going. I actually don't know what happens if you don't have SHELL
defined, but adding it to crontab
makes it easy to tell what is what.
The crontab(5) manpage deals with your query by default it's /bin/sh
Several environment variables are set up automatically by the cron(8) daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line of the crontab?s owner. HOME and SHELL may be over- ridden by settings in the crontab; LOGNAME may not.
so adding
SHELL=/bin/bash
to the crontab file would change the shell accordingly.