#!/bin/sh # PD script. No warranty. Mangle to suit. # # this has the feature of apparently not changing the inode numbers # for files that are being backed up. # Before you rely on this, check and make sure that logs still go in the right # place after the rotation is done # ############################################################################### # # Configuration - adjust this!! # # change to suit. Designed for Solaris # MAILTO=admin@yourdomain.com LOGDIR1=/var/adm LOGDIR2=/var/log ARCHIVEDIR=/opt/archive LOGFILES1="ROUTER TCPLOG messages user kernel daemon lastlog mail" LOGFILES2="maillog blah foo" ZIPPER=/usr/local/bin/gzip # ############################################################################### LOCKFILE=/tmp/syslog_archive.lock [ -f $LOCKFILE ] && exit || echo "`date`: $$" > $LOCKFILE # if needed # /usr/bin/logger -t sysadm "*** Scheduled log rotation" datestamp=`date +%Y%m%d-%H%M%S` # group 1 cd $LOGDIR1 for f in $LOGFILES1 do archivename=`echo $f | tr "[:upper:]" "[:lower:]"`.$datestamp cat $f | $ZIPPER > ${ARCHIVEDIR}/${archivename}.gz cat /dev/null > $f done # group 2 cd $LOGDIR2 for f in $LOGFILES2 do archivename=`echo $f | tr "[:upper:]" "[:lower:]"`.$datestamp cat $f |/usr/local/bin/gzip > ${ARCHIVEDIR}/${archivename}.gz cat /dev/null > $f done # this is Solaris style, in case the syslog gets lost. Change to suit /etc/init.d/syslog stop sleep 1 /etc/init.d/syslog start rm $LOCKFILE # comment out mailto unless mail config resolved echo "`uname -n`: $LOGDIR1 logs ($LOGFILES1) and $LOGDIR2 logs ($LOGFILES2)\ rotated and archived to $ARCHIVEDIR at `date`" \ | mail -s "INFO: `uname -n` log rotation" $MAILTO exit 0