6

Ubuntu 7.10 server i386 clock/date/time won't stay in sync. Are their log files I can view to tell when the clock changes? For a temporary fix, I created a file in /etc/cron.hourly:

#!/bin/sh
ntpdate time.nist.gov

However, this still leaves a potential hour of unchecked time. Is there a cron.minutely? That would still leave a potential minute of unchecked time. I have read about CMOS battery problems, but what if this does not fix it? I'd like to be able to troubleshoot this as a completely software problem.

My squid logs are showing dates back in 2005 when the clock changes, and my time-sensitive access controls are skewed and end up allowing users to surf prohibited websites during business hours.

4 Answers 4

14

The advice about running ntpdate is good, but it'll only step your time. A better option is to install ntpd and use it to keep the local clock synchronised, avoiding skewed logs.

With Ubuntu you should just be able to do apt-get install ntp. That should install ntpdate and ntpd, configure them to use ntp.ubuntu.com as the only server and synchronise time. For completeness you'll want to add other NTP servers (eg 0.pool.ntp.org, 1.pool.ntp.org and 2.pool.ntp.org).

6
  • 3
    ntpd is really the way to go. Running ntpdate with cron can give you some unwanted effects. Mar 25, 2010 at 13:01
  • 1
    +1 Ntpd is what the pros use. Though you can run cron at any time down to the second. The benefit of ntpd is that the time change isn't instantaneous. It changes the time to match the real time over a short period, so things that were scheduled don't get skipped, or run erratically. Mar 25, 2010 at 14:36
  • The package name for the ntp daemon and utilities on my Ubuntu 9.10 system is "ntp" rather than "ntpd". Mar 26, 2010 at 16:01
  • 1
    The Ubuntu package uses the -g flag by default, which allows ntpd to accept any time difference at startup only. It will step the time if it's over 128 ms, slew otherwise.
    – Cry Havok
    Mar 26, 2010 at 19:30
  • 1
    thanks, i monitored for about 5 hours this morning. seems to be working. had to upgrade to 8.04.4 LTS to install. system had not been maintained in awhile :)
    – David Fox
    Mar 27, 2010 at 17:02
3

I had the same problem yesterday but under Slackware 8. To make a long story short, I read a lot on google to finally reimage the computer. My manager sent me that link but it did not fixed my issue.

I changed the local to UTC time. I changed the timezome to have the good one I ln both.

Hope this will help you!

Also, you can try this:

ntpdate 0.pool.ntp.org
hwclock --systohc
1

I had the same trouble on a Debian Lenny system (it was an ancient Ubuntu 7.04 install prior to that) due to some flaky chipset on the decade-old motherboard. Here's my cron solution; for my purposes, twice daily keeps it sufficiently sync'd, and then once weekly it syncs and saves to the hardware clock (which is rock solid on my system).

Put this in /etc/cron.d/ntpsync:

# /etc/cron.d/ntpsync: run ntpdate-debian twice daily, sync hwclock once weekly

# run at 11:23 (am & pm) (update system clock)
23 11,23        * * *   root    test -x /usr/sbin/ntpdate-debian && /usr/sbin/ntpdate-debian  2>&1 | logger -i

# run at 11:59pm fridays (update system clock & save to hwclock)
59 23   * * 5   root    test -x /usr/sbin/ntpdate-debian && test -x /etc/init.d/hwclock.sh && /usr/sbin/ntpdate-debian && /etc/init.d/hwclock.sh restart 2>&1 | logger -i

This uses the standard crontab syntax for setting times and days, so it can get minutely if you want it that fine-grained. The "logger -i" at the end of the command chain sends the output to syslog's cron logging facilities.

0

You can set up a cron for that.

In /etc/crontab add the line

* * * * * root ntpdate time.nist.gov > /dev/null

You can achive this by as root (or a superuser) type

echo '* * * * * root /usr/sbin/ntpdate time.nist.gov > /dev/null' >> /etc/crontab


prerequisite: ntpdate to be installed in VM

apt-get update apt-get install ntpdate

3
  • can you explain how this would work?
    – David Fox
    Mar 25, 2010 at 12:32
  • It's super-important to remember to use two (2) ">" sings before /etc/crontab, if you do like I did, and start with one... you overwrite the file /etc/crontab with just the new line, instead of adding it do the end.
    – Gnutt
    Mar 25, 2010 at 13:11
  • 3
    Just do "crontab -e" to open it in an editor. Scripting stuff into your crontab isn't really something you want to do on a regular basis: it makes the file messy and hard to read (as well as potentially over-writing it if you miss your >). Mar 25, 2010 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .