克伦每天跑两次

在我的CentOS 7服务器上,夜间备份脚本生成的错误应该正常运行,这让我检查了我的cron活动。 我发现cron.daily正在运行两次 – 这是/var/log/cron的相关部分,在删除备份脚本以查看它是否以某种方式导致问题之后:

 Oct 10 02:28:01 mail CROND[1750]: (root) CMD (run-parts /etc/cron.hourly) Oct 10 02:28:01 mail run-parts(/etc/cron.hourly)[1750]: starting 0anacron Oct 10 02:28:01 mail anacron[1759]: Anacron started on 2017-10-10 Oct 10 02:28:01 mail run-parts(/etc/cron.hourly)[1761]: finished 0anacron Oct 10 02:28:01 mail anacron[1759]: Normal exit (0 jobs run) Oct 10 02:30:01 mail CROND[1766]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 02:40:01 mail CROND[1847]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 02:50:01 mail CROND[1936]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 03:00:01 mail CROND[2032]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 03:10:01 mail CROND[2148]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 03:17:01 mail CROND[2223]: (root) CMD (run-parts /etc/cron.daily) Oct 10 03:17:01 mail run-parts(/etc/cron.daily)[2223]: starting kizunademo Oct 10 03:17:02 mail run-parts(/etc/cron.daily)[2259]: finished kizunademo Oct 10 03:17:02 mail run-parts(/etc/cron.daily)[2223]: starting logrotate Oct 10 03:17:02 mail run-parts(/etc/cron.daily)[2266]: finished logrotate Oct 10 03:17:02 mail run-parts(/etc/cron.daily)[2223]: starting man-db.cron Oct 10 03:17:02 mail run-parts(/etc/cron.daily)[2277]: finished man-db.cron Oct 10 03:20:01 mail CROND[2288]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 03:28:01 mail CROND[2367]: (root) CMD (run-parts /etc/cron.hourly) Oct 10 03:28:01 mail run-parts(/etc/cron.hourly)[2367]: starting 0anacron Oct 10 03:28:01 mail anacron[2376]: Anacron started on 2017-10-10 Oct 10 03:28:01 mail run-parts(/etc/cron.hourly)[2378]: finished 0anacron Oct 10 03:28:01 mail anacron[2376]: Will run job `cron.daily' in 35 min. Oct 10 03:28:01 mail anacron[2376]: Jobs will be executed sequentially Oct 10 03:30:01 mail CROND[2381]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 03:40:01 mail CROND[2462]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 03:50:02 mail CROND[2547]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 04:00:01 mail CROND[2670]: (root) CMD (/usr/lib64/sa/sa1 1 1) Oct 10 04:03:01 mail anacron[2376]: Job `cron.daily' started Oct 10 04:03:01 mail run-parts(/etc/cron.daily)[2685]: starting kizunademo Oct 10 04:03:02 mail run-parts(/etc/cron.daily)[2721]: finished kizunademo Oct 10 04:03:02 mail run-parts(/etc/cron.daily)[2685]: starting logrotate Oct 10 04:03:02 mail run-parts(/etc/cron.daily)[2728]: finished logrotate Oct 10 04:03:02 mail run-parts(/etc/cron.daily)[2685]: starting man-db.cron Oct 10 04:03:03 mail run-parts(/etc/cron.daily)[2739]: finished man-db.cron Oct 10 04:03:03 mail anacron[2376]: Job `cron.daily' terminated Oct 10 04:03:03 mail anacron[2376]: Normal exit (1 job run) 

为什么cron.daily运行两次? 正如你所看到的,日志包含了一些与第二次运行相关的条目,这些条目在第一次运行时不存在:两行宣布即将到来的运行,另外两行表示以正常退出结束。 第一次运行简单地运行脚本没有额外的夸张。 我认为这意味着什么,但我不知道是什么。

我检查了所有我能想到的东西的双打。 我很确定我已经读过关于这个主题的每一个类似的线程,所以在调用这个重复的问题之前比较下面的内容。 基于为什么cron运行两次? 我检查了额外的进程 – ps aux | grep cron的完整输出 ps aux | grep cron如下,所以只有一个过程:

 root 9383 0.0 0.2 112672 2340 pts/0 S+ 15:18 0:00 grep --color=auto cron root 25624 0.0 0.0 126248 320 ? Ss Sep30 0:02 /usr/sbin/crond -n 

基于Cron作业运行两次 – Ubuntu服务器12.04我也检查了crontab -l -u root ,它表示no crontab for root

这里是我的/ etc / crontab:

 SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin [email protected] 28 * * * * root run-parts /etc/cron.hourly 17 3 * * * root run-parts /etc/cron.daily 44 2 * * 0 root run-parts /etc/cron.weekly 8 2 7 * * root run-parts /etc/cron.monthly 

思考?

为什么cron.daily运行两次?

crond正在运行一次:

 Oct 10 03:17:01 mail CROND[2223]: (root) CMD (run-parts /etc/cron.daily) 

anacron正在运行一次:

 Oct 10 04:03:01 mail anacron[2376]: Job `cron.daily' started 

crond开始anacron ,这就是为什么你没有看到它的过程:

 Oct 10 03:28:01 mail CROND[2367]: (root) CMD (run-parts /etc/cron.hourly) Oct 10 03:28:01 mail run-parts(/etc/cron.hourly)[2367]: starting 0anacron Oct 10 03:28:01 mail anacron[2376]: Anacron started on 2017-10-10 Oct 10 03:28:01 mail run-parts(/etc/cron.hourly)[2378]: finished 0anacron Oct 10 03:28:01 mail anacron[2376]: Will run job `cron.daily' in 35 min. Oct 10 03:28:01 mail anacron[2376]: Jobs will be executed sequentially