Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 9
    When running on an AWS Linux AMI, it didn't even occur to me that cron wouldn't be using /bin/bash as the shell. I kept wondering why things like cd /path/to/project; source .vars would work when I typed them manually but would fail (File not found) when included in a cronjob. The key line for me was setting SHELL=/bin/bash so that I could actually use familiar bash commands in each cronjob. /bin/sh/ (the default cron shell, apparently) is very limiting. Commented Sep 9, 2016 at 14:05
  • It's too bad you can't specify Environment Files at the top of the cron like you can specify individual environment variables. Systemd has a EnvironmentFile service unit. Too bad cron doesn't have something similar. Commented Jan 30, 2018 at 20:19
  • 5
    If $SHELL is /bin/sh, the source command does not exist. Use . instead. Commented Jan 25, 2019 at 21:35
  • The solution is not working for SunOS 5.9. The following error is displayed: SHELL=/bin/bash crontab: error on previous line; unexpected character found in line. crontab: errors detected in input, no crontab file generated Commented Jun 19, 2019 at 12:54
  • Hmm... I haven't used Sun in years but maybe their version of crontab doesn't support setting a default shell. In your case I would then have something along the lines of */1 * * * * /bin/bash $HOME/cron_job.sh. Commented Jun 20, 2019 at 2:21