V8/usr/lib/uucp/uudemon.cleanu

#!/bin/sh
#	@(#)uudemon.clea	1.7
#
#	This demon cleans up uucp directories.
#	It is started by /usr/lib/crontab;
#	it can be run daily, weekly, whatever depending on the system
#	  uucp load.
#	The log files get large so you may have to up the ulimit.
#	e.g.
#
# 45 23 * * * ulimit 5000; /bin/su uucp -c "/usr/lib/uucp/uudemon.cleanu"
#

MAILTO=${mailto:-uucp}
export PATH
PATH=/bin:/usr/bin:/usr/lib/uucp:/usr/lbin
TMP=/tmp/uu$$
WISDOM=/tmp/uv$$
>$WISDOM; chmod 0700 $WISDOM

#
#	These are taken from the Makefile.  If changed in Makefile
#	they must be changed here also.
#
PUBDIR=/usr/spool/uucppublic
SPOOL=/usr/spool/uucp
LOCKS=/usr/spool/locks
XQTDIR=/usr/spool/uucp/.Xqtdir
CORRUPT=/usr/spool/uucp/.Corrupt
LOGDIR=/usr/spool/uucp/.Log
SEQDIR=/usr/spool/uucp/.Sequence
STATDIR=/usr/spool/uucp/.Status
WORKDIR=/usr/spool/uucp/.Workspace
ADMIN=/usr/spool/uucp/.Admin

#	OLD is the directory for archiving old admin/log files
OLD=$SPOOL/.Old
O_LOGS=$OLD/Old-Log

mv $ADMIN/xferstats $OLD/xferstats
mv $ADMIN/audit $OLD/audit
mv $ADMIN/errors $OLD/errors
mv $ADMIN/Foreign $OLD/Foreign

> $ADMIN/xferstats
> $ADMIN/audit
> $ADMIN/errors
> $ADMIN/Foreign

#
#	The list in the for controls how many old LOG files are retained.
#	O_LOGS-2 goes to O_LOGS-3, O_LOGS-1 goes to O_LOGS-2.
#	Todays goes to O_LOGS-1
#
max=${1:-1}
for i in `seq $max -1 2`
do
	j=`expr $i - 1`
	mv ${O_LOGS}-$j ${O_LOGS}-$i
done

#
#	Combine all log files into O_LOGS-1.
#	Add a name separator between each system.
#
> ${O_LOGS}-1
for i in uucico uucp uux uuxqt
do
	cd $LOGDIR/$i
	for j in *
	do
		if [ "$j" = "*" ]
		then
			break
		fi
		echo "********** $j **********" >> ${O_LOGS}-1
		cat $j >> ${O_LOGS}-1
		rm -f $j
	done
done

#	Execute the system directory cleanup program
#	See uucleanup.1m for details.
uucleanup -D7 -C7 -X2 -o2 -W1
#	Use the grep instead of the mv to ignore warnings to uucp
# grep -v 'warning message sent to uucp' $ADMIN/uucleanup > $OLD/uucleanup
mv $ADMIN/uucleanup $OLD/uucleanup
if [ -s $OLD/uucleanup ]
then
	(echo "cleanup:"; cat $OLD/uucleanup) >>$WISDOM
fi
>$ADMIN/uucleanup

#  cleanup funny directories that may have been created in the spool areas
for d in $SPOOL/[A-z]*
do
	if [ -z "`ls $d`" ]; then
		continue
	fi

	cd $d
	for s in *
	do
		if [ "$s" = "*" ]
		then
			break
		fi
		if [ -d $s ]
		then
			rm -fr $s
		fi
	done

#		if it is now empty, remove it.
	cd ..
	rmdir $d
done 2>&1 >/dev/null

#
#	Find old cores
#
find $SPOOL -name core -print > $TMP
if [ -s $TMP ]
then
	(echo "cores:"; cat $TMP) >>$WISDOM
fi

#
#	Remove old files and directories
#
find $PUBDIR -type f -mtime +30 -exec rm -f "{}" \;
find $PUBDIR/* -type d -exec rmdir "{}" \;
find $SEQDIR -mtime +30 -exec rm -f "{}" \;
find $WORKDIR -mtime +1 -exec rm -f "{}" \;
find $STATDIR -mtime +2 -exec rm -f "{}" \;
find $CORRUPT -mtime +10 -exec rm -f "{}" \;

rm -f $LOCKS/LTMP*
rmdir $SPOOL/[A-z]* 2>/dev/null

#
#	Mail a daily summary of status
#
grep passwd ${O_LOGS}-1 > $TMP
# grep "REQUEST.*/" ${O_LOGS}-1 >> $TMP
if [ -s $TMP ]
then
	(echo "passwd requests:"; cat $TMP) >>$WISDOM
fi

awk '/(DENIED)/	{print prev}
		{prev = $0}' ${O_LOGS}-1 > $TMP
if [ -s $TMP ]
then
	(echo "denied:"; cat $TMP) >>$WISDOM
fi
# 
# uustat -q > $TMP
# if [ -s $TMP ]
# then
# 	(echo "Subject: uu-status"; cat $TMP) >>$WISDOM
# fi

ls $CORRUPT > $TMP
if [ -s $TMP ]
then
	(echo "$CORRUPT:"; cat $TMP) >>$WISDOM
fi

tail $OLD/errors 2>/dev/null > $TMP
tail $OLD/Foreign 2>/dev/null >> $TMP
if [ -s $TMP ]
then
	(echo "Admin stuff:"; cat $TMP) >>$WISDOM
fi
# (echo "Subject: uucleanup ran; $SPOOL du"; du $SPOOL) >>$WISDOM

if [ -s $WISDOM ]; then
	mail $MAILTO <$WISDOM
fi
rm -f $WISDOM

#
#	Dispose of mail to uucp and nuucp
#
# rm -f $MAILDIR/uucp $MAILDIR/nuucp $TMP
rm -f $TMP