RHEL6 の cron と anacron について

以下が、参考 URL

http://d.hatena.ne.jp/enakai00/20111004/1317718773

http://aikotobaha.blogspot.jp/2011/02/rhel6-7cronanacron.html

http://luna2-linux.blogspot.jp/2013/01/centos6-crondaily-centos5.html

 

anacron のジョブが実行されるまでは以下の流れになる (と思われる)

 

1.crond 

 

   ↓

 

2./etc/cron.d/0hourly※crond により /etc/cron.d は毎分チェックされている

------------------------------

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

01 * * * * root run-parts /etc/cron.hourly

^^毎時 1 分に /etc/cron.hourly が実行される (要するに /etc/cron.hourly/0anacron)

------------------------------

 

   ↓

 

3./etc/cron.hourly/0anacron

------------------------------

      :    :

/usr/sbin/anacron -s

^^^^^^^^^^^^^^^^^anacron が実行 (-s なのでジョブは 1 つ 1 つ実行)

------------------------------

 

   ↓

 

4./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

^^^^^^^^^^^^0 分から 45 分の間開始が遅延する。

 

# the jobs will be started during the following hours only

START_HOURS_RANGE=3-22

^^^^^^^^^^^^^^^^^^^^^^3 時台から 22 時台の間にジョブを実行する。

                      通常は、3 時台に実行するが、この時にサーバが停止している場合は、次の時間帯 (4 時台とか) になる。

 

#period in days   delay in minutes   job-identifier   command

1       5       cron.daily              nice run-parts /etc/cron.daily

^★1    ^★2

 

7       25      cron.weekly             nice run-parts /etc/cron.weekly

@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

------------------------------

★1:前回の実行からこの日数が経過している、処理が実行される。

    前回の実行のタイミングは /var/spool/anacron/cron.xxxx に記録。

 

★2:個別の遅延時間

 

 

以上を踏まえて、02:00 に /etc/cron.daily の処理を開始したい場合は、以下の設定変更

が必要となる。

 

 

1./etc/cron.d/0hourly

------------------------------

      :    :

00 * * * * root run-parts /etc/cron.hourly

^^★00 に変更

------------------------------

 

 

2./etc/anacrontab

------------------------------

      :    :

RANDOM_DELAY=0

             ^★0 に変更

 

# the jobs will be started during the following hours only

START_HOURS_RANGE=2-22

                  ^^^^2 時台に実行されない場合は 3 時台、4 時台、…

 

#period in days   delay in minutes   job-identifier   command

1       0       cron.daily              nice run-parts /etc/cron.daily

        ^★0 に変更

 

7       25      cron.weekly             nice run-parts /etc/cron.weekly

@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

------------------------------

 

 

以上となる。