로그인
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 179
192 리눅스 테스트 프로그램 하록 2012-07-10 613
191 hpux sshd 소스 컴파일시 하록 2012-07-09 2550
190 iscsi 설정 하록 2012-06-21 490
189 리눅스 dm-0같은 볼륨 확인 방법 [1] 하록 2012-06-18 567
188 php 파일 실행시 내용 보여줄때.. 하록 2012-03-14 473
187 vi 한글 쓰기... [1] 하록 2011-12-08 859
186 프로세스 별 Disk I/O 확인 방법 file 하록 2011-11-02 1609
185 sysrq 값에 대한 자료 하록 2011-11-01 549
184 lsof 포트 확인 방법 하록 2011-10-26 690
183 linux NTFS 사용... file 하록 2011-06-28 600
182 사용중인 포트의 프로세스 찾기 하록 2011-06-02 719
181 passwd, shadow 필드 설명 하록 2011-05-04 1107
180 hadoop 미사용 서버 확인.. 하록 2011-04-15 611
179 Too many open files in system 해결 방법... 하록 2011-04-13 1052
178 rcmd: socket: All ports in use 하록 2011-04-07 2677
177 nfs - nfs fstab 형식과 옵션 하록 2011-03-28 928
176 http error 메세지 하록 2011-03-25 521
175 FTP Error 메세지... 하록 2011-03-25 556
174 보안을 위한 /etc/sysctl.conf 파일 수정 하록 2011-03-22 527
» logrotate Shell 파일.... 하록 2011-02-01 361