0

I have an Amazon Linux AMI with this in crontab:

0 7 * * 1 root /usr/bin/wget -q http://localhost/digest_weekly.php -O - >> /var/log/digest_weekly.log

This calls the script digest_weekly.php every Monday at 7am. This script collects some data from the database and sends an email to each user. It returns a list of all the email addresses to which it sent an email. Today it had to send 2608 emails. The script takes a while to execute, but I can't see timeout errors in my logs.

The problem is that the mails are sent again every 15 minutes. /var/log/digest_weekly.log is empty, so I guess that the job didn't finish and somehow cron is launching it again after giving it some time. I see this in the Apache access logs:

127.0.0.1 - - [23/May/2016:07:00:01 +0000] "GET /digest_weekly.php HTTP/1.1" 200 70941 "-" "Wget/1.16.1 (linux-gnu)"
127.0.0.1 - - [23/May/2016:07:15:02 +0000] "GET /digest_weekly.php HTTP/1.1" 200 70941 "-" "Wget/1.16.1 (linux-gnu)"
127.0.0.1 - - [23/May/2016:07:30:04 +0000] "GET /digest_weekly.php HTTP/1.1" 200 70917 "-" "Wget/1.16.1 (linux-gnu)"

But in /var/log/cron I can see only one line:

May 30 07:00:01 ip-172-31-8-62 CROND[8104]: (root) CMD (/usr/bin/wget -q http://localhost/digest_weekly.php -O - >> /var/log/synkratos/digest_weekly.log)

Other cron jobs are executed just fine (hourly, daily).

Why is this cron job repeated? Last week it was executed 4 times, today 9 (until I killed the task).

  • 2
    -q (quiet) argument to populate log file will never work. – maxxvw May 30 '16 at 12:32
6

It is not a cron issue, rather wget restarting the download after reaching the default timeout of 900 seconds:

--read-timeout=seconds Set the read (and write) timeout to seconds seconds. The "time" of this timeout refers to idle time: if, at any point in the download, no data is received for more than the specified number of seconds, reading fails and the download is restarted. This option does not directly affect the duration of the entire download.
Of course, the remote server may choose to terminate the connection sooner than this option requires. The default read timeout is 900 seconds.

Rather than executing your PHP script by calling a web server you should probably run the script from the commandline PHP interpreter, i.e. something along the lines of:

0 7 * * 1 root /usr/bin/php /path/to/digest_weekly.php  >> /var/log/digest_weekly.log
0

Are you sure it is really cron (at least that line) who sends the requests? The fastest way to check: comment out that line and check cron logs later.

Perhaps there's another schedule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.