Monday, March 9, 2015

ubuntu - My cron tasks report command not found




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


Answer



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 ...

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...