1,"/etc/crontab"文件
[root@localhost ~]# more /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed
2,检查crond服务是否启动,crontab命令格式后,还是无法同步。查看crontab日志
From root@localhost.localdomain Sat Feb 13 00:43:01 2010 Return-Path: <root@localhost.localdomain> X-Original-To: root Delivered-To: root@localhost.localdomain Received: by localhost.localdomain (Postfix, from userid 0) id B340060ADA00; Sat, 13 Feb 2010 00:43:01 +0800 (CST) From: "(Cron Daemon)" <root@localhost.localdomain> To: root@localhost.localdomain Subject: Cron <root@localhost> root ntpdate -u 192.168.10.10 Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated Precedence: bulk X-Cron-Env: <XDG_SESSION_ID=68> X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0> X-Cron-Env: <LANG=en_US.UTF-8> 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> Message-Id: <20100212164301.B340060ADA00@localhost.localdomain> Date: Sat, 13 Feb 2010 00:43:01 +0800 (CST) /bin/sh: root: command not found
3,发现"/bin/sh: root: command not found",需要改成绝对路径
[root@localhost ~]# whereis crontab crontab: /usr/bin/crontab /etc/crontab /usr/share/man/man1/crontab.1.gz /usr/share/man/man5/crontab.5.gz [root@localhost ~]# whereis clock clock: /usr/sbin/clock /usr/share/man/man8/clock.8.gz
[root@localhost ~]# crontab -e 30 3 * * * /usr/sbin/ntpdate -u 192.168.10.10; /usr/sbin/clock -w