I'm trying to have a daily cron update the clock on my 12.04 server. I've followed the instructions here, but it still doesn't run: After a few weeks, the clock once again is off by a few seconds. I've been Googling around for solutions, but nothing seems to help. From what I've found on Google, I've verified the following:

Running the script manually works fine:

root@...:~# /etc/cron.daily/ntpdate
13 May 14:42:22 ntpdate[6927]: adjust time server offset -0.018984 sec

The script is executable:

root@...:~# ls -l /etc/cron.daily/
total 60
-rwxr-xr-x 1 root root    46 May 12 20:41 ntpdate

I don't see any cron-related errors in the syslog.

May 13 06:25:01 ... CRON[6704]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))

I've used an absolute path, just in case the cron PATH was missing it:

/usr/sbin/ntpdate ntp.ubuntu.com pool.ntp.org

I've done a dry run:

root@...:~# run-parts --test /etc/cron.daily

I can't see any reason why it wouldn't be working.

  • Will you give the output of the command when running it from the console? – L. D. James May 13 '14 at 21:00
  • Alright, edited my question to include that. – Theron Luhn May 13 '14 at 21:43

Ensure you have a shebang "#!/bin/bash" to specify howthe script is to be parsed.

ntpdate script:

/usr/sbin/ntpdate ntp.ubuntu.com pool.ntp.org

As an alternative to using cron, you could just install ntp and let the daemon automatically adjust the clock for you while the server is running.

  • Yes, this is better than running a cron. It's also very easy: help.ubuntu.com/lts/serverguide/NTP.html – steve Nov 28 '15 at 9:12
  • But in some cases it doesn't work: for example in virtual machines, even if deamon ntp/ntpd is running, the system clock after weeks can be moved few minutes from the correct time. And in that situations there is need to stop ntpd,run ntpdate, run ntpd. – Jack Feb 23 '17 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.