Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron jobs going out early

Status
Not open for further replies.

Haraldo

Programmer
Jun 9, 2003
41
GB
I've been asked to work out why some cron jobs happen before their supposed to. Has anyone come accross this problem?

I've been assured that our crons were setup correctly. If anyone has any information on this, or has experienced it too and may understand why it happens, i would appreciate hearing from you.

Chears HB
 
How about listing the crontab entry for a task that's misbehaving.
Also, please show the output of "date" command

Would also be useful for you to describe what the magnitude of "early" is.

D.E.R. Management - IT Project Management Consulting
 
In my experience cron does not run "early".
I would say there two main possibilities :

1) The clock on the machine is wrong (run "date" as thedaver suggested).
2) The jobs to be run by cron have been set up incorrectly.



--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks for the responses.

I can assure you that the date is not wrong on our live machines and we have very experienced developers setting up the cron jobs.

I ran a quick test yesterday and left it running from about mid day until now 09.55 - infact i'll keep monitoring it.

I have noticed one entry that went out early:

2005-06-14 23:59:00
2005-06-15 00:00:00
2005-06-15 00:00:57 <-
2005-06-15 00:02:00
2005-06-15 00:03:00

I have a php script set up in the cron to echo out the date and time as seen above. I'm running this test on our dev platform. Its funny that it happens on two machines (our live and our dev) not necessarily setup the same. Therefore its likey this is a cron issue.

As you can see it started 3 seconds early. Both the cron and the echo are working from the system clock so why does it go early?

Crontab setup:

* * * * /usr/websites/harrydev/html/cron_time_test.php >> /usr/websites/harrydev/html/cron_time_test_log.log

Chears, HB
 
Made a mistake with the copy & paste: (5 stars not 4)

* * * * * /usr/websites/harrydev/html/cron_time_test.php >> /usr/websites/harrydev/html/cron_time_test_log.log

Chears, HB
 
I am completely confused here.
To my understanding, cron has a resolution of minutes, not seconds.
Even then there is a 60 second possible window within which a process can be started.
You appear to be complaining that cron is occasionally not firing your process exactly on the second.
To my mind, you've been lucky as hell to see it anything like that close!

Why don't you ask your very experienced developers if they agree, and if not, maybe you can post the crontab entry to demonstrate how exactly you are defining a precise second start point.

BTW: Had you considered that someone might be playing the old "tin of elbow grease" trick on you?


Trojan.

 
Sorry, missed the crontab entry from your posts.
But still there are 5 asterisks so I see no evidence of an entry for seconds.


Trojan.

 
From the crontab manual page:

field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

No seconds!!!

Trojan.
 
KenCunningham - Thats made us think a bit...

We do have a cron that checks an NTP server at midnight:

After a simple test this does have an effect on the timings. The cron is below:

0 12 * * * rdate -s 193.5.216.14 || rdate -s time.nist.gov

However this may solve some of our troubles but we still notice some of our crons going out early where no NTP server is queried. Thanks for the help.

Just as long as we know that these crons are not going to go out minutes too early we can cater for that.

Chears, HB
 
Trojan - when referring to seconds im referring to my php time i'm echoing.

What i can see is that at the time above (c below):

"2005-06-15 00:00:57"

The midnight cron (00:00:00) has already gone. Therefore by checking the seconds im noticing that within the same minute another cron is launching (at 57 seconds past). My crons are set up to go every minute (obviously). So why is this happening?

Chears, HB
 
Haraldo,

The point I was making (very poorly I think) is that it is generally accepted that cron can be as much as 1 minute out from the time you specify so being 3 seconds out it not a complete surprise.
I accept that you might not expect it to be early, but is it possible that the others are actually 1 minutes late and this one is merely 57 seconds late?
I suggest that if you want something to run repeatedly and accurately every minute then cron is not the best tool for that job with a generally accepted resolution of 1 minute.



Trojan.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top