it-swarm.cn

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

cron.daily(和.weekly.hourly)中的条目何时运行,并且可配置?

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

我正在运行RHEL5和CentOS 4,但对于其他发行版/平台也将非常有用。

209
warren

对于发行版,您提到:

在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

因此,cron.daily的运行时间为04:02 am。

与CentOS 4.8相同

156
Richard Holloway

从手册页:

 Cron also searches for /etc/anacrontab

/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

也可以看看 man anacrontab

79
leonbloy

对于CentOS 6,您需要grep/etc/anacrontab,如果服务器/笔记本电脑/ 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

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

** 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

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

44
Spechal

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

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

14
darklion

在Ubuntu上,您将在/ etc/crontab文件中找到该文件的配置位置。我猜这在RH和Centos上是类似的。

9
Sven

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

百胜安装cronie-noanacron

百胜清除cronie-anacron

然后,您现在可以使用/etc/cron.d/dailyjobs为您的每日,每周和每月工作配置最佳计划时间。

5
Daniel Santos

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

我系统上的解决方案就像运行crontab -l作为根:

[email protected]:~# 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
4
paddy

来自/etc/anacrontab在我的Ubuntu 9.10系统上:

1       5       cron.daily       Nice run-parts --report /etc/cron.daily
7       10      cron.weekly      Nice run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly Nice run-parts --report /etc/cron.monthly
3

就Solaris而言,没有这种功能。只需将常规crontab条目用于日常任务即可。

2
jlliagre

OpenSuse 42.x更新:

/ etc/crontab显示文件/ usr/lib/cron/run-crons,该文件应该每15分钟运行一次。

/ usr/lib/cron/run-crons依次(有可能的代码行)在/ etc/sysconfig/cron中寻找名为DAILY_TIME的变量

该文件显示;

# At which time cron.daily should start. Default is 15 minutes after booting
# the system. Example setting would be "14:00".
# Due to the fact that cron script runs only every 15 minutes,
# it will only run on xx:00, xx:15, xx:30, xx:45, not at the accurate time
# you set.

DAILY_TIME=""

将其设置为所需的时间,然后通过以下方式重新启动cron:

systemctl restart cron.service
1
MarcoZen