`cron.daily` 什么时候运行?

war*_*ren 226 linux redhat centos cron

cron.daily(and .weeklyand .hourly) 中的条目何时运行,是否可配置?

我还没有找到一个明确的答案,希望有一个。

我正在运行 RHEL5 和 CentOS 4,但对于其他发行版/平台也很好。

Ric*_*way 174

对于您提到的发行版:

在 CentOS 5.4 上(对于 RHEL5 应该相同)

grep run-parts /etc/crontab

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
Run Code Online (Sandbox Code Playgroud)

所以 cron.daily 在凌晨 04:02 运行。

在 CentOS 4.8 上相同

  • 这对于 CentOS 6 或更高版本不再有效,向下滚动以获取更多信息。 (4认同)
  • 这背后有什么原因吗?我只能假设这是服务器上最安静的时间。 (2认同)

leo*_*loy 85

从手册页:

 Cron also searches for /etc/anacrontab
Run Code Online (Sandbox Code Playgroud)

/etc/anacrontab 在我的系统(Fedora 12)中:

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
Run Code Online (Sandbox Code Playgroud)

也可以看看 man anacrontab

  • “CentOS 6”就是这种情况。谢谢。 (8认同)
  • 这意味着每“1”天凌晨 5 点?对不起,但这没有任何答案。 (4认同)
  • @elysch 让我重复我回答的最后一行:另见“man anacrontab” (3认同)
  • anacron 的很好解释 [here](http://www.thegeekstuff.com/2011/05/anacron-examples/)。基本上,**anacron** **没有固定的启动时间**,而是会根据最后一个进程运行的时间启动进程,并具有指定的延迟。如果机器在进程 ** 应该运行 ** 时关闭,那么它会在机器重新启动时启动进程,在指定的延迟之后(除非没有特殊范围+随机延迟,请参阅@spechal 的回答)。 (3认同)
  • @mbrownnyc 还有 CentOS-7 (3认同)

Spe*_*hal 48

对于 CentOS 6,您需要 grep /etc/anacrontab 并且如果 server/laptop/dekstop/etc 是否已关闭,答案会有所不同。

cat /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
Run Code Online (Sandbox Code Playgroud)

因此,在凌晨 3 点到晚上 10 点**(重新启动后和机器启动 5 分钟后^^)之间,运行 /etc/cron.daily。如果没有重新启动,作业应该在 3:05AM++ 运行。

** As defined by START_HOURS_RANGE
^^ As defined by FIELD_TWO (i.e. the 5 after the 1 in the cron.daily line)
++ plus a random time between 0 and 45 minutes as defined by RANDOM_DELAY
Run Code Online (Sandbox Code Playgroud)

参考:http : //linux.die.net/man/5/anacrontab


小智 16

对于 SuSE 系统(特别是 SLES 11.1 和 openSuSE 10.3),/etc/ cron.daily脚本的每日运行时间由/etc/sysconfig/cron文件中设置的DAILY_TIME变量的值控制。

如果未设置 DAILY_TIME 变量,则默认为:(上次启动时间 + 15 分钟)。


Sve*_*ven 10

在 Ubuntu 上,您会找到一个文件 /etc/crontab,它是从那里配置的。我想它在 RH 和 Centos 上是类似的。

  • 这是适用于 Ubuntu Lucid 10.04 LTS 的正确文件。我的默认设置是 cron.daily 的早上 6:25。 (2认同)

小智 6

CentOS6.x/RedHat6.x 默认安装 cronie-anacron 软件包。你必须:

yum 安装 cronie-noanacron

百胜擦除 cronie-anacron

然后,您现在拥有 /etc/cron.d/dailyjobs 来为您的每日、每周和每月工作配置最佳计划时间。

  • 如果安装了 anacron,您不能按照此处的其他评论编辑 /etc/anacrontab 而不是卸载它吗? (3认同)

小智 5

我使用 Slackware (14.0),但没有/etc/crontab. 此外,anacron不是发行版的一部分。

我系统上的解决方案就像crontab -l以 root身份运行一样简单:

root@flea:~# crontab -l
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system.  If a script fails, run-parts will
# mail a notice to root.
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
Run Code Online (Sandbox Code Playgroud)