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