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 online=1 for psupply in AC ADP0 ; do sysfile="/sys/class/power_supply/$psupply/online" if [ -f $sysfile ] ; then if [ `cat $sysfile 2>/dev/null`x = 1x ]; then online=1 break else online=0 fi fi done if [ $online = 0 ]; then exit 0 fi /usr/sbin/anacron -s
range_start != -1 && range_stop != -1 && x x166 (t->tm_hour < range_start || t->tm_hour >= range_stop)) x x167 { x x168 Debug(("The job `%s' falls out of the %02d:00-%02d:00 hours range, skipping.", x x169 jr->ident, range_start, range_stop)); x >x170 xclose (jr->timestamp_fd); x x171 return 0; x x172 } x x173 } x x174
/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=0 # the jobs will be started during the following hours only START_HOURS_RANGE=3-12 #period in days delay in minutes job-identifier command 1 1 cron.daily nice run-parts /etc/cron.daily 7 2 cron.weekly nice run-parts /etc/cron.weekly @monthly 3 cron.monthly nice run-parts /etc/cron.monthly ]# ls -l /var/spool/anacron/ total 8 -rw-------. 1 root root 5 Nov 23 14:43 cron.daily -rw-------. 1 root root 10 Nov 23 14:36 cron.weekly ]# grep . /var/spool/anacron/* /var/spool/anacron/cron.daily:2021 /var/spool/anacron/cron.weekly:202111011
2021 Anacron started on 2021-11-23 Will run job `cron.daily' in 1 min. Will run job `cron.monthly' in 3 min. Jobs will be executed sequentially Job `cron.daily' started Job `cron.daily' terminated Job `cron.monthly' started Job `cron.monthly' terminated Normal exit (2 jobs run) START_HOURS_RANGE の範囲外でしたが、 cron.daily と cron.monthly が実行され ました。 今回は RANDOM_DELAY を 0 としているので、delay-in-minutesがそのまま遅延時間 として用いられスケジュールされています。
at 0x33d3: file lock.c, line 90. (gdb) r // cron.weekly まで進める (gdb) p jr->command $5 = 0x555555765920 "nice run-parts /etc/cron.weekly" (gdb) p b $6 = 8 (gdb) p timestamp $7 = "20211101" (gdb)
/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=0 # the jobs will be started during the following hours only START_HOURS_RANGE=3-16 #period in days delay in minutes job-identifier command 1 1 cron.daily nice run-parts /etc/cron.daily 7 2 cron.weekly nice run-parts /etc/cron.weekly @monthly 3 cron.monthly nice run-parts /etc/cron.monthly ]# ls -l /var/spool/anacron/ total 12 -rw-------. 1 root root 9 Nov 23 15:28 cron.daily -rw-------. 1 root root 9 Nov 23 15:29 cron.monthly -rw-------. 1 root root 9 Nov 23 15:29 cron.weekly ]# grep . /var/spool/anacron/* /var/spool/anacron/cron.daily:20211122 /var/spool/anacron/cron.monthly:20211101 /var/spool/anacron/cron.weekly:20211101
2021 Anacron started on 2021-11-23 Checking against 22 with 31 Will run job `cron.daily' in 1 min. Will run job `cron.weekly' in 2 min. Jobs will be executed sequentially Job `cron.daily' started Job `cron.daily' terminated Job `cron.weekly' started Job `cron.weekly' terminated Normal exit (2 jobs run) 想定通り、 cron.daily, cron.weekly が実行され終了しました。
Nov 23 15:42:06 localhost anacron[9793]: Anacron started on 2021-11-23 Nov 23 15:42:06 localhost anacron[9793]: Will run job `cron.daily' in 1 min. Nov 23 15:42:06 localhost anacron[9793]: Will run job `cron.weekly' in 2 min. Nov 23 15:42:06 localhost anacron[9793]: Jobs will be executed sequentially Nov 23 15:43:06 localhost anacron[9793]: Job `cron.daily' started Nov 23 16:13:06 localhost anacron[9793]: Job `cron.daily' terminated Nov 23 16:13:06 localhost anacron[9793]: Job `cron.weekly' started Nov 23 16:13:06 localhost anacron[9793]: Job `cron.weekly' terminated Nov 23 16:13:06 localhost anacron[9793]: Normal exit (2 jobs run)