B3log Solo

Aixe

Welcome to Aixe Blog

ntpdate无法在cron里更新系统时间 有更新!

2011-10-12 16:56:40 c.beyondblack
1  评论    497  浏览

首先非常感谢师兄帮我解决这个问题,并专门写了一篇文章来提醒我,在此深深的感谢。为了更好的记住,我也转载了这篇日志

crontab -e插入ntpdate更新命令,如下所示: 

*/5 * * * * ntpdate time.nist.gov 

单独用命令更新ntpdate time.nist.gov系统时间,却是正常的. 

但是放到cron里面计划任务,系统时间更新不正常. 

查看cron日志如下,有进行执行,但是命令好象没有生效. 

tail -n 40 /var/log/cron 

Sep 28 11:30:01 CentOS5 crond[3139]: (root) CMD (ntpdate time.nist.gov)
Sep 28 11:35:01 CentOS5 crond[3165]: (root) CMD (ntpdate time.nist.gov)

通过命令,显示每五分钟执行一次是正常的.但是系统时间还是无法更新.

在root的邮件里面提示ntpdate,如下: 

From: [url=mailto:root@localhost.localdomain]root@localhost.localdomain [/url] (Cron Daemon)
To: [url=mailto:root@localhost.localdomain]root@localhost.localdomain [/url]
Subject: Cron < [url=mailto:root@localhost]root@localhost [/url]> ntpdate time.nist.gov  
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root> 
/bin/sh: ntpdate: command not found 

提示ntpdate找不到命令,于是用ntpdate绝对路径/usr/sbin/ntpdate放入cron里. 

仍旧提示/bin/sh: /usr/bin/ntpdate: command not found 


在cron里面添加的是
/usr/sbin/ntpdate,还是解决不了.

根据这句提示 :X-Cron-Env: <PATH=/usr/bin:/bin>

我把ntpdate复制到/usr/bin目录下面.现在同步时间很正常了.

原来cron计划任务,调用的是/usr/bin的可执行文件,ntpdate在cron里正常运行.

cron, crond, 系统时间, 自动更改, crontab, 更新
新一篇:Linux rpm命令 旧一篇:Apache虚拟主机配置
Ansen
回复  |  2011-11-23 16:32:02
[dmtsai@www ~]$ crontab -e
# 此时会进入 vi 的编辑画面让您编辑工作!注意到,每项工作都是一行。
0 12 * * * mail dmtsai -s "at 12:00" < /home/dmtsai/.bashrc
#分 时 日 月 周 |<==============命令串========================>|

发表评论

validate

最新评论

评论最多的文章

访问最多的文章

分类标签

友情链接

存档

TOP