【问题标题】:Crontab File Empty But Jobs RunningCrontab 文件为空但作业正在运行
【发布时间】:2019-01-08 12:44:39
【问题描述】:

我很难理解一些 cron 行为,我想知道是否有人能够阐明这一点。

我有一台运行 Centos 6.6 的服务器。如果我运行“sudo cat /etc/crontab”,会显示以下输出:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# 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

如您所见,系统 crontab 文件中没有配置实际作业。但是,正如您从 /var/log/cron 文件中看到的那样,作业确实是从 /etc/cron.d/、/etc/cron.daily/ 和 /etc/cron.hourly/ 目录运行的:

Jul 29 03:38:01 <servername> run-parts(/etc/cron.daily)[26524]: finished logrotate
Jul 29 03:38:01 <servername> run-parts(/etc/cron.daily)[26494]: starting update_phishing_sites
Jul 29 03:42:04 <servername> run-parts(/etc/cron.daily)[26565]: finished update_phishing_sites
Jul 29 03:42:04 <servername> run-parts(/etc/cron.daily)[26494]: starting update_spamassassin
Jul 29 03:45:02 <servername> run-parts(/etc/cron.daily)[26587]: finished update_spamassassin
Jul 29 03:45:02 <servername> anacron[26044]: Job `cron.daily' terminated (mailing output)
Jul 29 03:45:02 <servername> anacron[26044]: Normal exit (1 job run)
Jul 29 04:01:01 <servername> CROND[26719]: (root) CMD (run-parts /etc/cron.hourly)
Jul 29 04:01:01 <servername> run-parts(/etc/cron.hourly)[26719]: starting 0anacron
Jul 29 04:01:01 <servername> run-parts(/etc/cron.hourly)[26728]: finished 0anacron
Jul 29 04:01:01 <servername> run-parts(/etc/cron.hourly)[26719]: starting check_MailScanner
Jul 29 04:01:02 <servername> run-parts(/etc/cron.hourly)[26752]: finished check_MailScanner
Jul 29 04:01:02 <servername> run-parts(/etc/cron.hourly)[26719]: starting processing_messages_alert
Jul 29 04:01:02 <servername> run-parts(/etc/cron.hourly)[26766]: finished processing_messages_alert
Jul 29 04:01:02 <servername> run-parts(/etc/cron.hourly)[26719]: starting update_bad_phishing_sites
Jul 29 04:08:37 <servername> run-parts(/etc/cron.hourly)[26863]: finished update_bad_phishing_sites
Jul 29 04:08:37 <servername> run-parts(/etc/cron.hourly)[26719]: starting update_virus_scanners
Jul 29 04:14:52 <servername> run-parts(/etc/cron.hourly)[27187]: finished update_virus_scanners

我的问题是,这些工作是什么/在哪里/如何开始的?我在网上看到过 /etc/crontab 文件看起来像这样的示例:

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

如果我的 /etc/crontab 文件包含这些条目,那么我将了解这些作业是如何开始的。但是如上所述,我的 /etc/crontab 文件不包含这些条目。

克里斯

【问题讨论】:

  • 您能否通过运行crontab -e 来显示用户特定的 crontab 文件的内容?
  • @roelofs,感谢您的回复并尝试提供帮助。我实际上最终弄清楚了,请参阅下面的答案。我挣扎了很长时间才弄清楚……在发布问题之前,我应该坚持一段时间。

标签: cron


【解决方案1】:

我应该在发布问题之前再花几分钟时间调查一下,因为我发现了这些工作是如何开始的。我服务器上 crond 的手册页说明如下:

/etc/crontab
          system  crontab.   Nowadays the file is empty by default.  Originally it was usually used to run daily, weekly, monthly jobs.  By default these jobs
          are now run through anacron which reads /etc/anacrontab configuration file.  See anacrontab(5) for more details.

如果我查看 /etc/anacrontab 文件,它包含以下内容:

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days   delay in minutes   job-identifier   command
1       5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

所以,这就是他们被踢掉的方式。 :)

【讨论】:

  • 我没有看到每小时作业的命令。这些也有效吗?
猜你喜欢
  • 2021-04-26
  • 1970-01-01
  • 2018-05-05
  • 2020-09-04
  • 1970-01-01
  • 2020-07-11
  • 2013-11-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多