如何改变时间cron.daily在Linux中运行

我有一个cron.daily脚本,每天早上在特定的时间运行。 我需要改变它运行的时间。

如何更改时间cron.daily运行脚本?

在Red Hat风格的系统上,这是在/etc/crontab

默认情况下,cron.daily脚本在4:02运行。 编辑这个文件将修改那个时间。

 # 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 

在Debian / Ubuntu系统上,这也在/etc/crontab控制。

例如; 默认的Ubuntu 12.04安装:

 # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # mh dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) # 

无论哪种情况,您都可以在这里find更多关于使用什么语法的细节: http : //linux.die.net/man/5/crontab或者在几乎任何Linux系统上运行man 5 crontab

在openSUSE上,crontab如下所示:

 SHELL=/bin/sh PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin MAILTO=root # # check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly # -*/15 * * * * root test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1 

run-crons命令会validation/var/spool/cron/lastrun中的文件的时间戳。 当自上次执行以来的时间到期时,它将再次运行cron文件。

时间可以通过触摸文件来影响。 例如,将其设置为2012-11-17 03:15:

 touch -t 201211140315 /var/spool/cron/lastrun/cron.daily 

在RHEL / CentOS 6及以上版本

 # /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 

如果线路不在那里,这不会解决任何问题。

尝试find哪里cron.daily提到,与

 grep -R cron.daily /etc 

然后从那里拿走。

你想做两件事情:

  1. 从cron.daily删除脚本,并放在别的地方。
  2. 将一个条目添加到您的crontab中以在指定的时间运行指定的脚本:

00 10 * * * /path/to/script