변군이글루

[리눅스] CentOS 7 Anacron 본문

서___리눅스

[리눅스] CentOS 7 Anacron

변군 변군이글루 2017.08.18 13:37

Anacron
: anacron은 정확한 시각에 작업을 실행하는 용도가 아니라 매일, 매주, 매달의 작업을 '적절한 타이밍'에 실행하기 위한 명령어

 

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

 

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

 

각필드의 의미
period in days : 최근 실행 일 (단위 : 일)
delay in minutes : 부팅 이후 명령어를 실행할 시간(단위 : 분)
job-identifier : 로그에 기록할 경우 사용할 구분자
                nice is the command to execute jobs with a lower priority (by default 10),
                run-parts is a shell script returning all the files in a given directory.
command : 실행할 명령어

 

anacron 마지막 작업 실행일 기록 파일(job-identifier)
# ls -l /var/spool/anacron/*
---
-rw-------. 1 root root 9  8월 18 03:50 /var/spool/anacron/cron.daily
-rw-------. 1 root root 9  8월  4 00:49 /var/spool/anacron/cron.monthly
-rw-------. 1 root root 9  8월 18 03:06 /var/spool/anacron/cron.weekly
---

 

# cat /var/spool/anacron/* 
---
20170818
20170804
20170818
---

 

logrotate
# cat /etc/cron.daily/logrotate
#!/bin/sh

 

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

 

[원본URL] RHEL7: How to get started with anacron.
https://www.certdepot.net/rhel7-how-get-started-anacron/

 

0 Comments
댓글쓰기 폼