Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crontab with wget - why is it running twice?

Tags:

wget

crontab

I've a php script which runs from webservice and insert to DB.

crontab -e

......other cron tasks above.......
...
..
..
# Run test script.php at 1610
10 16 * * * /usr/bin/wget -q -O /home/username/my_cronjobs/logs/cron_adhoc http://localhost/project/script.php

Apparently, at 16:10, this script is run twice! 16:10:01 and 16:25:02

Is it something wrong and gotta do with using wget?? Or did i set the schedule on cron job wrongly?

When i run http://localhost/project/script.php from browser, it will only run once..

Any idea regarding this problem ?

I've tested, there are no other users running the same job... I suspect the way wget works.

As my script needs at least 20mins to complete without sending back a response (it is pulling alot of data from webservicces and save to db) .. suspect there's a time out or retry of wget by default causing this problem.

like image 936
flyclassic Avatar asked Dec 16 '10 07:12

flyclassic


People also ask

What is wget in cron job?

The wget command is a command line utility for downloading files from the remote servers. It's also used to triggers server side scripts using the cron jobs.


3 Answers

The wget docs give a default read-timeout of 900 seconds, or 15 minutes.

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 is why you were seeing the file called again 15 minutes later. You can specify a longer read-timeout by adding the parameter and an appropriate number of seconds:

--read-timeout=1800
like image 200
joshuahedlund Avatar answered Oct 16 '22 23:10

joshuahedlund


i think i solve my own question.

My php takes some time to load, i guess wget retries or time out after some default specified time.

I solved it by using /usr/bin/php

like image 27
flyclassic Avatar answered Oct 17 '22 01:10

flyclassic


Whose user's crontab is this?

Check if there is another user for which you set up cron job at different time and forgot about it.

like image 1
Goran Jovic Avatar answered Oct 17 '22 00:10

Goran Jovic