#!/bin/sh # # Program: Logfile rotation utility # # Author: Matty # # 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/messages /var/log/syslog /var/log/maillog /var/log/openldap" 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 # Restart syslog /etc/init.d/syslog stop && /etc/init.d/syslog start