7

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 96.44.142.5 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
...
/etc/cron.daily/ntpdate
...

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

2
  • Will you give the output of the command when running it from the console? May 13, 2014 at 21:00
  • Alright, edited my question to include that. May 13, 2014 at 21:43

2 Answers 2

3

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

ntpdate script:

#!/bin/bash
/usr/sbin/ntpdate ntp.ubuntu.com pool.ntp.org
0
2

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.

2
  • Yes, this is better than running a cron. It's also very easy: help.ubuntu.com/lts/serverguide/NTP.html
    – ray1
    Nov 28, 2015 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, 2017 at 15:12

You must log in to answer this question.

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