我正在尝试每天更新 12.04 服务器上的时钟。我已按照此处的说明操作,但它仍然无法运行:几周后,时钟再次关闭了几秒钟。我一直在谷歌搜索解决方案,但似乎没有任何帮助。根据我在 Google 上的发现,我验证了以下内容:
手动运行脚本工作正常:
root@...:~# /etc/cron.daily/ntpdate
13 May 14:42:22 ntpdate[6927]: adjust time server 96.44.142.5 offset -0.018984 sec
Run Code Online (Sandbox Code Playgroud)
该脚本是可执行的:
root@...:~# ls -l /etc/cron.daily/
total 60
....
-rwxr-xr-x 1 root root 46 May 12 20:41 ntpdate
....
Run Code Online (Sandbox Code Playgroud)
我在系统日志中没有看到任何与 cron 相关的错误。
May 13 06:25:01 ... CRON[6704]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
Run Code Online (Sandbox Code Playgroud)
我使用了绝对路径,以防万一 cron PATH 丢失了它:
/usr/sbin/ntpdate ntp.ubuntu.com pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
我做了一个试运行:
root@...:~# run-parts --test /etc/cron.daily
...
/etc/cron.daily/ntpdate
...
Run Code Online (Sandbox Code Playgroud)
我看不出为什么它不起作用的任何理由。
确保您有一个“#!/bin/bash”符号来指定如何解析脚本。
ntpdate脚本:
#!/bin/bash
/usr/sbin/ntpdate ntp.ubuntu.com pool.ntp.org
Run Code Online (Sandbox Code Playgroud)