/etc/cron.hourly、/etc/cron.dailyなどのスクリプトは自動的に実行されますか?

/etc/cron.hourly、/etc/cron.dailyなどのスクリプトは自動的に実行されますか?

アイテムが/etc/cron.d/自動的に実行されることを知っています。ところで私もこんなことを発見した/etc/

/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/

/etc/cron.d/私は次のようなものを見つけました0hourly

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

または名前のファイルがありません*daily*monthly*weekly

/etc/cron.hourlyここにスクリプトを追加すると自動的に実行されるという意味ですか?/etc/cron.daily、およびのスクリプトでは/etc/cron.monthly/これは起こりませんか/etc/cron.weekly/

編集する:

/etc/crontabMyは初期化された変数SHELLPATHおよびを除いて空です。MAILTO

/etc/cron.hourly/私が見つけたスクリプトは今日実行されていることを0anacron確認するようです。cron.daily私も/etc/anacronこれが含まれていることを発見しました:

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

読書を少しさせてくれたと思います。特にanacron(8)そしてanacrontab(5)

ベストアンサー1

CentOSはこの点でUbuntuと非常によく似ていますが、設定は少し異なります。 Ubuntuはanacronを使用して毎日/週/月のタスクを実行し、/etc/crontabに設定されます/etc/anacrontab

CentOSの場合、まず次のようになります。

# cat /etc/cron.hourly/0anacron
#!/bin/sh
# Check whether 0anacron was run today already
if test -r /var/spool/anacron/cron.daily; then
    day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
    exit 0;
fi

# Do not run jobs when on battery power
if test -x /usr/bin/on_ac_power; then
    /usr/bin/on_ac_power >/dev/null 2>&1
    if test $? -eq 1; then
    exit 0
    fi
fi
/usr/sbin/anacron -s

1日1回anacronを確認/実行した後:

# 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

毎日、毎週、毎月crontabが構成されます。

おすすめ記事