66

Is it possible to make commands in crontab run with bash instead of sh? I know you can pass commands to bash with -c, but that's annoying and I never use sh anyway.

  • don't really know what you're doing (not familiar with cron) but if you are running a script then adding a shebang to it should work, not sure if I am correct. – Alvin Wong Oct 11 '13 at 17:18
95

You should be able to set the environment variable prior to the cron job running:

SHELL=/bin/bash
5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
  • 2
    is it possible to also make it read .bashrc? – Fluffy Oct 10 '13 at 15:46
  • 3
    @Fluffy .bashrc is - by definition - for interactive shells; so when started via cron, bash will only read this file if it is an interactive shell. – umläute Oct 10 '13 at 16:03
  • 1
    @umläute, ok, so where should I put env vars that should exist in non-interactive non-login shells? – Fluffy Oct 10 '13 at 16:06
  • 17
    I was able to make it read bashrc by adding BASH_ENV="/root/.bashrc". Thanks – Fluffy Oct 10 '13 at 16:12
  • 2
    @Fluffy you should make that an answer – vol7ron Apr 11 '17 at 21:37

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.