My cron tasks report command not found

5,926

Solution 1

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

Solution 2

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
Share:
5,926

Related videos on Youtube

MonoThreaded
Author by

MonoThreaded

Awesome!

Updated on September 18, 2022

Comments

  • MonoThreaded
    MonoThreaded over 1 year

    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

  • MonoThreaded
    MonoThreaded over 12 years
    Is there a way to add to the default path for cron so I don't have to provide the full path for each command?
  • user9517
    user9517 over 12 years
    Yes you can specify a PATH in the crontab file - see my edit