0

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?

  • (oops elicited a rtfm. My bad, looked at man crontab but not man 5 crontab) – artfulrobot Mar 26 '15 at 11:07
2

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.

6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.