#!/bin/csh -f
# $Id: log-maint,v 1.5 1994/06/13 20:14:07 vikas Exp vikas $
#
# daily/weekly maintenance for NOCOL log files. Move old logs and then sighup
# the noclogd process.
#
## Tweak these
##
## TOP = "/nocol" ?  OPSMAIL = "ops@your.domain" ?
##
set TOP = "<TOP>"
set OPSMAIL = "<OPSMAIL>" 	# to get email from logstats
set LOGFILE = "critical"		# noclogd log file for 'logstats'

set LOGDIR = "${TOP}/logs"
set OLD = "${LOGDIR}/old"
set PIDFILE = "${TOP}/etc/noclogd.pid"

set LOGSTATS = "${TOP}/bin/logstats"	# location of the script
set MAIL = "/usr/ucb/mail"

## Set KEEPOLD to the number of old log file revisions that you want
set KEEPOLD = "6"
set COMPRESS = "compress"		# compress or gzip

if ( ! -d $LOGDIR ) then
   echo "$0 - Log directory $LOGDIR not found, exiting"
   exit 1
endif
if ( ! -d $OLD ) mkdir $OLD
if ( ! -d $OLD ) then
   echo "$0 - Could not make directory $OLD, exiting"
   exit 1
endif

cd $LOGDIR

## Run logstats to send out the reports
if ( -x ${LOGSTATS} && -e ${LOGFILE} ) then
    ${LOGSTATS} ${LOGFILE}  | $MAIL -s "logstats" $OPSMAIL
endif

foreach f ( * )
 if ( -f $f ) then
   @ j = $KEEPOLD - 1
   while ( $j > 0 )
	@ i = $j - 1
	if ( -f $OLD/$f.$i.Z ) mv $OLD/$f.$i.Z $OLD/$f.$j.Z
	@ j = $i
   end
   ${COMPRESS} -c $f >! $OLD/$f.0.Z
   cp /dev/null $f
 endif
end

#
sleep 5;
kill -HUP `head -1 $PIDFILE`
exit 0
##
