cron.daily
(和.weekly
和.hourly
)中的条目何时运行,并且可配置?
我还没有找到确切的答案,希望有一个答案。
我正在运行RHEL5和CentOS 4,但对于其他发行版/平台也将非常有用。
cron.daily
(和.weekly
和.hourly
)中的条目何时运行,并且可配置?
我还没有找到确切的答案,希望有一个答案。
我正在运行RHEL5和CentOS 4,但对于其他发行版/平台也将非常有用。
Answers:
对于发行版,您提到:
在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相同
grep run-parts /etc/crontab
只需查找有关何时为每个目录调用运行部件的说明。
从手册页:
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
CentOS 6
。谢谢。
对于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
在Ubuntu上,您将在/ etc / crontab文件中找到该文件的配置位置。我猜这在RH和Centos上是类似的。
CentOS6.x / RedHat6.x默认安装软件包cronie-anacron。你必须:
百胜安装cronie-noanacron
百胜清除cronie-anacron
然后,您现在可以使用/etc/cron.d/dailyjobs为您的每日,每周和每月作业配置最佳计划时间。
我使用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
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