로그인
Sign in
#!/bin/sh
#
# Program: Logfile rotation utility <logrotate.sh>
#
# Author: Matty <matty91 at gmail dot com>
#
# Current Version: 1.0
#
# Revision History:
#
# Version 1.0
#     Original release
#
# Last Updated: 10-09-2005
#
# Purpose:
#   This script will rotate the logfiles listed in the LOG variable. COUNT vopies
#   will be maintained.
#

# Set some global environment variables
PATH=/bin:/usr/bin:/usr/ucb ; export PATH

# Trap signals sent when we are moving files so we don't get interrupted
trap '' 0 1 2 3 9 15

# GLOBAL VARIABLES
COUNT=10
LOGS="/var/adm/syslog/syslog.log /var/adm/syslog/mail.log /var/opt/resmon/log/event.log /var/adm/cron/log /var/adm/xferlog /var/adm/wtmp"
STOPVALUE=0

# LOOP till no more logs
for i in ${LOGS}
do
        # Reset the indice
        INDICE=${COUNT}
        while [ ${INDICE} -ge ${STOPVALUE} ]
        do
                # Add one to the present index
                PLUSONE=`expr ${INDICE} + 1`

                # if the logfile exists move it to LOG.INDEX + 1
                test -f ${i}.${INDICE} && mv ${i}.${INDICE} ${i}.${PLUSONE}

                # Increment the index
                INDICE=`expr $INDICE - 1`
        done

        # Move the logfile to logfile.COUNT
        mv ${i} ${i}.${STOPVALUE}

        # zero out the logfile ( NEW LOGFILE )
        cp /dev/null ${i}
        chmod 644 ${i}
done
List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 자주 사용하는 명령어 제비게릴라 2019-06-27 20927
» logrotate Shell 파일.... 하록 2011-02-01 5768
172 logrotate 오류시... [1] 하록 2010-12-31 6552
171 parted 명령 [1] 하록 2010-11-04 6048
170 중복라인 한줄로 표시... 하록 2010-10-12 5929
169 chattr, lsattr 파일 속성 변경 하록 2010-08-20 5950
168 리눅스 커널 설정 [5] 하록 2010-08-19 6652
167 ext3 -> ext4로 변환 방법 하록 2010-08-17 5851
166 vi에서 한글 깨질때... 하록 2010-08-04 5824
165 tar 분할 압축....... 하록 2010-08-03 5804
164 subnet [1] 하록 2010-07-22 5779
163 Netmask [2] 하록 2010-07-22 5756
162 지수 표현 법.. 하록 2010-07-22 5795
161 root password 만료시.... 조치 방법 하록 2010-07-16 6076
160 리눅스 oom-killer [1] 하록 2010-06-29 7025
159 glance Log 체크 하록 2010-06-24 5533
158 e2label 방법... 하록 2010-06-11 5498
157 리눅스에서 iso 마운트 하기.... 하록 2010-05-31 5846
156 어제 날짜 구하기... [1] 하록 2010-05-28 5750
155 open ipmi 를 이용한 서버관리 하록 2010-05-10 5734
154 NFS에서 실행이나 카피가 안되는 경우 하록 2010-04-20 5645