#!/bin/sh # # This program rolls over old log files and creates new ones. # # The program loops through the list of files used by syslog, copies # the old data to a date and time stamped file, then truncates the # active log file. # # This program supports one command line option "-compress" or "-nocompress", # which controls whether or not the program compresses the archived log # file. The default behavior is controlled by the COMPRESS variable at the # start of the program. # # Andy Welter 9/23/98 # www.the-welters.com # COMPRESS="yes" USAGE="logroll [-compress|-nocompress]" LOGDIR=/var/adm/syslog FILES="auth.log daemon.log kern.log user.log syslog.log local0.log messages" DATE=`date +"%y%m%d"` case $1 in "-compress") COMPRESS=yes ;; "-nocompress") COMPRESS=no ;; *) echo $USAGE exit 1 ;; esac for F in $FILES; do FF="${LOGDIR}/${F}" if [ -f $FF ]; then while [ -f ${FF}.${DATE} ]; do DATE=`date +"%y%m%d.%H%M%S"` done cp -p $FF $FF.$DATE chgrp adm $FF.$DATE chmod 660 $FF.$DATE if [ "$COMPRESS" = "yes" ]; then /usr/bin/compress $FF.$DATE fi fi cat /dev/null > $FF chgrp adm $FF chmod 660 $FF done