Linux keep system time in sync with hardware clock

Status
Not open for further replies.
Joined
Aug 15, 2005
Messages
2,329
Location
Lexington, KY
I have some responsibility for an Ubuntu server whose system time loses about a minute a week. Users find this aggravating because it timestamps their activity wrong.

The hardware clock in this server stays correct, so I run this command to fix the system time:

hwclock -s

Is there an easy way to make Ubuntu do this automatically, perhaps daily? I have ssh access, no console.
 
Add it to cron to run daily.

But, the best way would be to set up ntpd as it will sync the clock with a real timeserver online and keep your clock accurate always. If you run something in cron you to sync your time daily it can 'shock' certain things because it adjusts the time immediately. If you do it with ntpd it adjusts the time gradually so no applications are affected.
 
Last edited:
Why aren't you using NTP? Does the server have access to the internet?

You could set up a cron job to do that command daily, monthly, whateverly.

Do a google search on crontab

edit; looks like someone beat me to it.
edit; sudo apt-get install ntp is all you have to do, ubuntu takes care of the setup.
 
Last edited:
Thank you for the replies. Yes, the server does have Internet access. I had hoped that Ubuntu has some shortcut to create this particular cron job, but I guess not. I believe Windows has long had a built-in feature to either (user's choice) regularly sync system time with the hardware clock or an Internet resource.

I installed ntp.
smile.gif
 
If you open a terminal and type ntpq -p it will show you how accurate the time is (within ms), where it is getting the time from. The sources are evaluated and a source that is not keeping good time is discarded.
 
A bit of background..

NTP is a very clever program. It makes certain that the reported time moves forward monotonically and consistently.

That means that the reported time never moves backwards, and each tick is pretty much the same length of time as the ticks before and after. The clock is just slowed or sped up slightly, never jumping or reversing.

This is vital for programs that calculate time differences and rates. They never expect the time elapsed to be a negative number (or even zero, with some system calls that measure time in nanoseconds or microseconds).

Also, if you screw this up, some people in the matrix will see the cat a second time.
 
Most hardware clocks are notoriously drifty--never rely on that if you can use NTP.

Simple_gifts is right. The NTP protocol is very resilient and robust.

I'm responsible for NTP on a medium-ish sized network (2000+ devices) and I even have my own stratum 1 time server. One mistake most people make is that they only list one or two servers in ntp.conf. There's no reason not to list 6 or 7 in there just to make sure you've got a reliable pool of servers to look at.
 
Originally Posted By: BearZDefect
Thank you for the replies. Yes, the server does have Internet access. I had hoped that Ubuntu has some shortcut to create this particular cron job, but I guess not. I believe Windows has long had a built-in feature to either (user's choice) regularly sync system time with the hardware clock or an Internet resource.

I installed ntp.
smile.gif


Yeah, windows uses ntp.
 
Status
Not open for further replies.
Back
Top