crontab 执行时间与系统时间不一致

来源:本站原创 Linux 超过2,244 views围观 0条评论

crontab 执行时间与系统时间不一致。

原因:之前改过时区:

解决 只要改过时间都需要重启crontab 服务,别想着只重启服务器。

 

[root@mysql01 download]# date
Wed Dec 27 09:24:05 CST 2017
[root@mysql01 download]# date
Wed Dec 27 09:24:11 CST 2017
[root@mysql01 download]# tail -f /var/log/cron
Dec 26 20:15:01
mysql01 CROND[3845]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:16:01 mysql01 CROND[3952]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:17:01 mysql01 CROND[4058]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:18:01 mysql01 CROND[4164]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)

重启测试

[root@mysql01 download]# systemctl status crond
● crond.service – Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-12-27 09:28:31 CST; 12s ago
Main PID: 5361 (crond)
   CGroup: /system.slice/crond.service
           └─5361 /usr/sbin/crond -n

Dec 27 09:28:31 mysql01 systemd[1]: Started Command Scheduler.
Dec 27 09:28:31 mysql01 systemd[1]: Starting Command Scheduler…
Dec 27 09:28:31 mysql01 crond[5361]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 93% if used.)
Dec 27 09:28:31 mysql01 crond[5361]: (CRON) INFO (running with inotify support)
Dec 27 09:28:31 mysql01 crond[5361]: (CRON) INFO (@reboot jobs will be run at computer’s startup.)
[root@mysql01 download]#
[root@mysql01 download]#
[root@mysql01 download]# !tail
tail -f /var/log/cron
Dec 26 20:23:01 mysql01 CROND[4695]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:24:01 mysql01 CROND[4805]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:25:01 mysql01 CROND[4913]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:26:01 mysql01 CROND[5021]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:27:01 mysql01 CROND[5126]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:28:01 mysql01 CROND[5244]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:28:31 mysql01 crond[2416]: (CRON) INFO (Shutting down)
Dec 26 20:28:31 mysql01 crond[5361]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 93% if used.)
Dec 26 20:28:31 mysql01 crond[5361]: (CRON) INFO (running with inotify support)
Dec 26 20:28:31 mysql01 crond[5361]: (CRON) INFO (@reboot jobs will be run at computer’s startup.)
Dec 26 20:29:01 mysql01 CROND[5367]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)=

 

然鹅,并没有如你所想

Dec 26 20:28:31 mysql01 crond[5361]: (CRON) INFO (@reboot jobs will be run at computer’s startup.)
Dec 26 20:29:01 mysql01 CROND[5367]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:30:01 mysql01 CROND[5472]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:31:01 mysql01 CROND[5580]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)

 

———-真实的解决方式。——————–

[root@mysql01 download]# systemctl start crond————–1

[root@mysql01 ~]# systemctl restart rsyslog—————–2
[root@mysql01 ~]#
[root@mysql01 ~]#
[root@mysql01 ~]#
[root@mysql01 ~]# systemctl status rsyslog
● rsyslog.service – System Logging Service
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-12-27 09:37:58 CST; 5s ago
Main PID: 6370 (rsyslogd)
   CGroup: /system.slice/rsyslog.service
           └─6370 /usr/sbin/rsyslogd -n

Dec 27 09:37:58 mysql01 systemd[1]: Starting System Logging Service…
Dec 27 09:37:58 mysql01 systemd[1]: Started System Logging Service.
[root@mysql01 ~]#
[root@mysql01 ~]#
[root@mysql01 ~]#
[root@mysql01 ~]# tail -f /var/log/cron
Dec 26 20:32:21 mysql01 crond[5361]: (CRON) INFO (Shutting down)
Dec 26 20:32:29 mysql01 crond[5803]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 30% if used.)
Dec 26 20:32:29 mysql01 crond[5803]: (CRON) INFO (running with inotify support)
Dec 26 20:32:29 mysql01 crond[5803]: (CRON) INFO (@reboot jobs will be run at computer’s startup.)
Dec 26 20:33:01 mysql01 CROND[5807]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:34:01 mysql01 CROND[5938]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:35:01 mysql01 CROND[6045]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:36:01 mysql01 CROND[6152]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 26 20:37:01 mysql01 CROND[6259]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)
Dec 27 09:38:01 mysql01 CROND[6376]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)

————解决——————————–
Dec 27 09:39:01 mysql01 CROND[6484]: (root) CMD (/bin/bash /opt/download/rehttp.sh http://192.168.142.138/nginx-logo.png 100)

——————–提醒————————————-

只要改时间,都建议将现运行的服务重启一遍

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=3651转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

您必须 [ 登录 ] 才能发表留言!