#!/bin/sh
: '/*********************************************************************
	uucp.daily
   
	Sccsid=@(#)uucp.daily	1.1.1 (2.11BSD) 1996/10/25

	usage:
		Called from cron in the wee early hours of the morning

	arguments:
		none.
   
	history:
		long time ago	original version
		07/02/82	revisions to month change handling
   *********************************************************************/'

: 'daily UUCP cleanup'
: 'called in the morning'

spool=/usr/spool/uucp
olddir="$spool/OLD"
PATH="/usr/new:/usr/ucb:/usr/local:/bin:/usr/bin" ; export PATH

/usr/bin/uulog
/usr/sbin/uuclean -m -p LCK. -p X. -p D. -p C. -p TM.
/usr/sbin/uuclean -p STST. -n 12

set `date`
day=$1
month=$2
daymon=$3

: '************************************************************
	Old spool/log files are kept by the naming scheme:
	LOGFILE.${day}${daymon} where ${day} is the day of
	the week (Sun-Sat), and ${daymon} is the numerical
	day of the month.  SYSLOG files are kept by the scheme:
	SYSLOG.week: the current weeks: totals; SYSLOG.month:
	the current months totals; SYSLOG.${month} where
	${month} is the first three letters of the month: the
	totals for that month.
   ************************************************************'
cd $spool
mv LOGFILE $olddir/LOGFILE.${day}${daymon}
mv SYSLOG SYSLOG.$$
cat SYSLOG.$$ >>$olddir/SYSLOG.week
rm -f SYSLOG.$$

: 'clean up UUCP logfiles'
cd $olddir

: 'save the current SYSLOG in a monthly summary
   each Monday.
   '
case $day in
Mon)	cat SYSLOG.week >>SYSLOG.month
	rm -f SYSLOG.week
	;;
esac

: 'Create monthly name file if necessary'
if [ ! -f logmonth ]
then
	echo $month >logmonth
	curmonth=$month
else
	curmonth=`cat logmonth`
fi

: 'If the month has wrapped around, save the monthly
   summary by the name of the month
  '
if [ $month != $curmonth ]
then
	if [ -f SYSLOG.week ]
	then
		cat SYSLOG.week >>SYSLOG.month
		rm -f SYSLOG.week
	fi
	mv SYSLOG.month SYSLOG.$curmonth
	echo $month >logmonth
	uuusage $curmonth >UUUSAGE.${curmonth}
fi

: 'Remove LOGFILEs older than three days; save SYSLOG
   files forever (remove manually)
   '
find . -name 'LOGFILE.*' -mtime +3 -exec rm -f {} \;
