1

Why is this cron job executing repeatedly over time and what can I do to stop it?

I have a cron job that is supposed to run at 4 each morning. It hits a php script that executes some daily data analysis and under normal conditions runs once (taking about 2-3 minutes to complete) and quits. It has been working but lately it is running amuck right about the time the server crashes. I investigated and found the following. The crontab entry looks like this:

* 4 * * * /usr/bin/wget -q -O /dev/null 'http://123.456.78.90/index/thing?param=1'

In my log file I see:

123.456.78.90 - - [28/Nov/2012:04:00:01 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4181 "-" "Wget/1.12 (linux-gnu)"
123.456.78.90 - - [28/Nov/2012:04:01:01 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4181 "-" "Wget/1.12 (linux-gnu)"
123.456.78.90 - - [28/Nov/2012:04:02:01 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4181 "-" "Wget/1.12 (linux-gnu)"
// and then later it ends with (note that it isn't trying every minute now)
123.456.78.90 - - [28/Nov/2012:05:28:09 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4182 "-" "Wget/1.12 (linux-gnu)"
123.456.78.90 - - [28/Nov/2012:05:29:36 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4182 "-" "Wget/1.12 (linux-gnu)"
123.456.78.90 - - [28/Nov/2012:05:29:00 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4182 "-" "Wget/1.12 (linux-gnu)"
123.456.78.90 - - [28/Nov/2012:06:06:51 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4181 "-" "Wget/1.12 (linux-gnu)"
123.456.78.90 - - [28/Nov/2012:06:06:53 -0800] "GET /index/thing?param=1 HTTP/1.0" 200 4181 "-" "Wget/1.12 (linux-gnu)"

Why would it show repeated runs like this? Is it not reaching something so it keeps trying? Any assistance is appreciated as this multiple runs thing is new to me.

Lothar_Grimpsenbacher
  • 1,677
  • 3
  • 19
  • 29

3 Answers3

6

Looks like you're running it every minute of the fourth hour of the day. So 60 copies of wget are getting fired up.

* 4 * * * .....

They then take however long they take. With 60 copies running, that's probably quite a while, explaining why some requests finish hours later.

If you really want it to run only once at exactly 4 am, then use:

0 4 * * * .....
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
3

If you want that wget to run each day at 4am, I would suggest changing your cron job to look like this:

0 4 * * * /usr/bin/wget -q -O /dev/null 'http://123.456.78.90/index/thing?param=1'

http://www.adminschoice.com/crontab-quick-reference

I suggest fixing that first then reporting back if you're still seeing an issue. Thanks.

JZeolla
  • 141
  • 3
1

http://www.gnu.org/software/wget/manual/wget.html

Wget has been designed for robustness over slow or unstable network connections; if a download fails due to a network problem, it will keep retrying until the whole file has been retrieved. If the server supports regetting, it will instruct the server to continue the download from where it left off.

I'd suspect it's timing out (the default is 900 seconds) and reattempting.

ceejayoz
  • 32,910
  • 7
  • 82
  • 106