113

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.

1
  • 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. Commented Oct 11, 2013 at 17:18

1 Answer 1

165

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
11
  • 3
    is it possible to also make it read .bashrc? Commented Oct 10, 2013 at 15:46
  • 5
    @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. Commented Oct 10, 2013 at 16:03
  • 31
    I was able to make it read bashrc by adding BASH_ENV="/root/.bashrc". Thanks Commented Oct 10, 2013 at 16:12
  • 4
    @Fluffy you should make that an answer Commented Apr 11, 2017 at 21:37
  • 4
    Regarding .bashrc, bash -l looks useful, blog.endpoint.com/2015/02/cron-wrapper-keep-your-cron-jobs.html Commented May 4, 2017 at 5:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.