Search code examples
bashubuntucurlcronbin

Cron job sometimes fails with error by curl


I made a cron job in (Ubuntu 14 Trusty), like this way:

sudo crontab-e

then

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    * * * * * curl --silent http://www....cron_script.php >  /dev/null

But sometimes, I get this error message to the crown job:

/etc/cron.hourly/curl:
/etc/cron.hourly/curl: line 5: bin: command not found
run-parts: /etc/cron.hourly/curl exited with return code 127

Can anybody tell me why? As you can see, it runs every minute, but once a hour I get that error message. Mostly on every hour at XX:54 minutes.

Thanks in advance!


Solution

  • Your crontab should'n contain the line:

    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    Since you've put the path in the crontab hourly script it executes every hour which make you error show up

    Create a script instead and put both lines in there

    #!/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    curl --silent http://www....cron_script.php
    

    then in crontab just run the script

    * * * * * my_script.sh >  /dev/null 2>&1
    

    Crontab should only contains lines which follows the format:

    m h dom mon dow command