4.3BSD-Tahoe/usr/adm/daily

#! /bin/sh -
PATH=/usr/local:/usr/ucb:/bin:/usr/bin:/etc
host=`hostname | sed -e 's/\..*//'`
echo "Subject: $host daily run output"

echo ""
echo "Removing scratch and junk files:"
if [ -d /tmp ]; then
	cd /tmp
	find .	! -name . -atime +3 -exec rm -f {} \;
	find .	! -name . -type d -mtime +1 -exec rmdir {} \; >/dev/null 2>&1
fi

#if [ -d /usr/tmp ]; then
#	cd /usr/tmp
#	find .	! -name . -atime +7 -exec rm -f {} \;
#	find .	! -name . -type d -mtime +1 -exec rmdir {} \; >/dev/null 2>&1
#fi

if [ -d /scratch ]; then
	cd /scratch
	find .	! -name . -atime +1 -exec rm -f {} \;
	find .	! -name . -type d -mtime +1 -exec rmdir {} \; >/dev/null 2>&1
fi

if [ -d /usr/preserve ]; then
	cd /usr/preserve
	find .	! -name . -mtime +7 -exec rm -f {} \;
fi

if [ -d /usr/spool/rwho ] ; then
	cd /usr/spool/rwho
	find .	-mtime +7 -exec rm -f {} \;
fi

find /	\( -name '[#,]*' -o -name '.#*' -o -name a.out -o -name core \
	   -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
		-a -atime +3 -exec rm -f {} \;
msgs -c
if [ -f /usr/new/lib/news/expire ]; then
	/usr/new/lib/news/expire
fi

echo ""
echo "Purging accounting records:"
cp /usr/adm/acct /usr/adm/acct.yesterday
/etc/sa -s > /dev/null

echo ""
echo "Backup passwd and group files:"
d=/usr/adm
if cmp $d/passwd.bak /etc/passwd >/dev/null; then :; else
	echo "$host passwd diffs:"
	diff $d/passwd.bak /etc/passwd
	mv $d/passwd.bak $d/passwd.bak2
	cp -p /etc/passwd $d/passwd.bak
fi
if cmp $d/group.bak /etc/group >/dev/null; then :; else
	mv $d/group.bak $d/group.bak2
	cp -p /etc/group $d/group.bak
fi
if [ -f /usr/local/lib/Distfile ]; then
	if cmp $d/Distfile.bak /usr/local/lib/Distfile >/dev/null; then :; else
		mv $d/Distfile.bak $d/Distfile.bak2
		cp /usr/local/lib/Distfile $d/Distfile.bak
	fi
fi

echo ""
echo "Running calendar:"
calendar -

echo ""
echo "Rotating mail syslog:"
cd /usr/spool/mqueue
rm -f syslog.7
if [ -f syslog.6 ]; then mv -f syslog.6  syslog.7; fi
if [ -f syslog.5 ]; then mv -f syslog.5  syslog.6; fi
if [ -f syslog.4 ]; then mv -f syslog.4  syslog.5; fi
if [ -f syslog.3 ]; then mv -f syslog.3  syslog.4; fi
if [ -f syslog.2 ]; then mv -f syslog.2  syslog.3; fi
if [ -f syslog.1 ]; then mv -f syslog.1  syslog.2; fi
if [ -f syslog.0 ]; then mv -f syslog.0  syslog.1; fi
mv -f syslog syslog.0
cp /dev/null syslog
chmod 644    syslog
kill -1 `cat /etc/syslog.pid`
cd /

if [ -d /usr/spool/uucp -a -f /usr/lib/uucp/clean.daily ]; then
	echo ""
	echo "Cleaning up UUCP:"
	echo /usr/lib/uucp/clean.daily | su daemon
fi

echo ""
echo ""
echo "Checking subsystem status:"
echo ""
echo "disks:"
df
echo ""
dump W
echo ""
sync
/etc/fsck -n | grep -v '^\*\* Phase'


echo ""
echo "mail:"
mailq

if [ -d /usr/spool/uucp ]; then
	echo ""
	echo "uucp:"
	uusnap
fi

echo ""
echo "network:"
netstat -i
echo ""
ruptime

echo ""
echo "SECURITY CHECKS:"
echo ""
d=/usr/adm
echo "checking setuid files in root filesystem:"
/etc/ncheck -s `awk -F: '$2=="/" {print $1}' /etc/fstab` | grep -v '	/dev/' \
	> $d/check.today
chmod 400 $d/check.today
if [ -f $d/check.yesterday ]
then
	if diff $d/check.today $d/check.yesterday > /tmp/dif; then :; else
		echo "*** New setuid files in root filesystem:"
		cat /tmp/dif
		mv $d/check.today $d/check.yesterday
	fi
	rm /tmp/dif
else
	cat $d/check.today
	mv $d/check.today $d/check.yesterday
fi
echo ""
echo "checking for uids of 0:"
awk 'BEGIN {FS=":"} $3=="0" {print $1,$3}' /etc/passwd

echo ""
if [ -f /usr/local/lib/Distfile ]; then
	echo "Running rdist:"
	rdist -f /usr/local/lib/Distfile 
fi