Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will using ntpd possibly mess up cron jobs?

Tags:

unix

cron

ntp

My system has a lot of time drift, after a couple of week it can be ahead by around 5 minutes.

To fix this, I installed ntp, which can help fix drift and of course sync the time to the ntp servers occasionally.

Suppose I have a cron job for something like backing up files. Is the following scenario possible?

02:00:00 - Cron starts a job
02:00:03 - Ntpd syncs time back 5 seconds to 01:59:58
02:00:00 - 2:00 gets repeated and cron job runs twice

If the cron job copies large files, the second run might try overwriting files the first job is not finished writing to.

Thanks!

like image 675
Matthew Avatar asked Nov 23 '25 14:11

Matthew


1 Answers

Here's what the cron(8) man page says (this is for Vixie cron; other implementations might behave differently):

Special considerations exist when the clock is changed by less than 3 hours, for example at the beginning and end of day‐ light savings time. If the time has moved forwards, those jobs which would have run in the time that was skipped will be run soon after the change. Conversely, if the time has moved backwards by less than 3 hours, those jobs that fall into the repeated time will not be re-run.

Only jobs that run at a particular time (not specified as @hourly, nor with '*' in the hour or minute specifier) are affected. Jobs which are specified with wildcards are run based on the new time immediately.

Clock changes of more than 3 hours are considered to be corrections to the clock, and the new time is used immediately.

like image 163
Keith Thompson Avatar answered Nov 28 '25 17:11

Keith Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!