8

This is the contents of my crontab file:

0 0,6,12,18 * * * cd /var/www/app/current && backup perform --trigger db_backup --config_file config/backup.rb --data-path db --log-path log --tmp-path tmp >> /var/www/app/current/log/cron.log 2>&1

0 3 * * * cd /var/www/app/current && RAILS_ENV=production bundle exec rake runs:populate --silent >> /var/www/app/current/log/cron.log 2>&1

59 23 * * * cd /var/www/app/current && RAILS_ENV=production bundle exec rake runs:log --silent >> /var/www/app/current/log/cron.log 2>&1

If I run any of these manually as the owner of the crontab they work fine, but the cron.log file simply contains:

/bin/sh: bundle: not found
/bin/sh: backup: not found
/bin/sh: bundle: not found

I tried wrapping each one in the following (as default by the whenever gem which I'm using to manage my cron file) bash -l -c '...' but then I get the same as above except for bash bash: bundle: command not found

DEfusion
  • 287
  • 3
  • 9

2 Answers2

13

The deafult PATH for CRON jobs is usually /usr/bin:/bin. Your commands bundle and backup are likely not in the default path. One solution is to change your crontab and include the full path to these commands.

0 0,6,12,18 * * * cd /var/www/app/current && /path/to/backup ...

etc. In general it's a good idea to use full paths in crontabs. If you want you can also specify the PTH inside the crontab

PATH=/bin:/usr/bin:/path/to/your/program

0 0,6,12,18 * * * cd /var/www/app/current && backup ...
user9517
  • 114,104
  • 20
  • 206
  • 289
3

Yes, you can set path before actual crontab records, eg:

PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:
0 3 * * * run-cron-job
user9517
  • 114,104
  • 20
  • 206
  • 289
Andrei Mikhaltsov
  • 2,987
  • 1
  • 22
  • 31