daily revision 1.44
1#!/bin/sh -
2#
3#	$NetBSD: daily,v 1.44 2001/12/18 00:48:05 lukem Exp $
4#	@(#)daily	8.2 (Berkeley) 1/25/94
5#
6
7export PATH=/bin:/usr/bin:/sbin:/usr/sbin
8umask 077
9
10if [ -s /etc/daily.conf ]; then
11	. /etc/daily.conf
12fi
13
14host=`hostname`
15date=`date`
16
17echo "To: ${MAILTO:-root}"
18echo "Subject: $host daily output for $date"
19echo ""
20
21if [ -f /etc/rc.subr ]; then
22	. /etc/rc.subr
23else
24	echo "Can't read /etc/rc.subr; aborting."
25	exit 1;
26fi
27
28if [ -z "$MAILTO" -o "$USER" != "root" ]; then
29	MAILTO=root
30fi
31
32echo ""
33echo "Uptime: " `uptime`
34
35# Uncommenting any of the finds below would open up a race condition attack
36# based on symlinks, potentially allowing removal of any file on the system.
37#
38#echo ""
39#echo "Removing scratch and junk files:"
40#if [ -d /tmp -a ! -h /tmp ]; then
41#	cd /tmp && {
42#	find . -type f -atime +3 -exec rm -f -- {} \;
43#	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
44#	    >/dev/null 2>&1; }
45#fi
46
47#if [ -d /var/tmp -a ! -h /var/tmp ]; then
48#	cd /var/tmp && {
49#	find . ! -name . -atime +7 -exec rm -f -- {} \;
50#	find . ! \( -name . -o -name vi.recover \) -type d \
51#		-mtime +1 -exec rmdir -- {} \; \
52#	    >/dev/null 2>&1; }
53#fi
54
55# Additional junk directory cleanup would go like this:
56#if [ -d /scratch -a ! -h /scratch ]; then
57#	cd /scratch && {
58#	find . ! -name . -atime +1 -exec rm -f -- {} \;
59#	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
60#	    >/dev/null 2>&1; }
61#fi
62
63#if [ -d /var/rwho -a ! -h /var/rwho ] ; then
64#	cd /var/rwho && {
65#	find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
66#fi
67
68DAILYDIR=`mktemp -d /tmp/_daily.XXXXXX` || exit 1
69
70trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
71
72if ! cd "$DAILYDIR"; then
73	echo "Can not cd to $DAILYDIR".
74	exit 1
75fi
76
77TMP=daily.$$
78TMP2=daily2.$$
79
80if checkyesno find_core; then
81	find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
82		-o -fstype null \
83		-o -fstype kernfs -o -fstype procfs \) -a -prune -o \
84		-name 'lost+found' -a -prune -o \
85		\( -name '*.core' -o -name 'core' \) -a -print > $TMP
86#		\( -name '[#,]*' -o -name '.#*' -o -name a.out \
87#		   -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
88#			-a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
89
90	egrep '\.core$|^core$' $TMP > $TMP2
91	if [ -s $TMP2 ]; then
92		echo ""
93		echo "Possible core dumps:"
94		cat $TMP2
95	fi
96
97#	egrep -v '\.core' $TMP > $TMP2
98#	if [ -s $TMP2 ]; then
99#		echo ""
100#		echo "Deleted files:"
101#		cat $TMP2
102#	fi
103
104	rm -f $TMP $TMP2
105fi
106
107if checkyesno run_msgs; then
108	msgs -c
109fi
110
111if checkyesno expire_news && [ -f /etc/news.expire ]; then
112	/etc/news.expire
113fi
114
115if checkyesno purge_accounting && [ -f /var/account/acct ]; then
116	echo ""
117	echo "Purging accounting records:"
118	mv /var/account/acct.2 /var/account/acct.3
119	mv /var/account/acct.1 /var/account/acct.2
120	mv /var/account/acct.0 /var/account/acct.1
121	cp /var/account/acct /var/account/acct.0
122	sa -sq
123fi
124
125if checkyesno run_calendar; then
126	calendar -a > $TMP
127	if [ -s $TMP ]; then
128		echo ""
129		echo "Running calendar:"
130		cat $TMP
131	fi
132	rm -f $TMP
133fi
134
135if checkyesno check_uucp && \
136    [ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then
137	echo ""
138	echo "Cleaning up UUCP:"
139	su daemon -c /usr/libexec/uucp/clean.daily
140fi
141
142if checkyesno check_disks; then
143	df -ki > $TMP 
144	dump -W > $TMP2
145	if [ -s $TMP -o -s $TMP2 ]; then
146		echo ""
147		echo "Checking subsystem status:"
148		echo ""
149		echo "disks:"
150		if [ -s $TMP ]; then
151			cat $TMP
152			echo ""
153		fi
154		if [ -s $TMP2 ]; then
155			cat $TMP2
156			echo ""
157		fi
158		echo ""
159	fi
160fi
161
162rm -f $TMP $TMP2
163
164if checkyesno check_mailq; then
165	mailq > $TMP
166	if ! grep -q "queue is empty$" $TMP; then
167		echo ""
168		echo "mail:"
169		cat $TMP
170	fi
171fi
172
173rm -f $TMP
174
175if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
176	(cd /tmp; su -m uucp -c "uustat -a") > $TMP
177	if [ -s $TMP ]; then
178		echo ""
179		echo "uucp:"
180		cat $TMP
181	fi
182fi
183
184rm -f $TMP
185
186if checkyesno check_network; then
187	echo ""
188	echo "network:"
189	netstat -inv
190	echo ""
191	t=/var/rwho/*
192	if [ "$t" != '/var/rwho/*' ]; then
193		ruptime
194	fi
195fi
196
197if checkyesno run_fsck; then
198	echo ""
199	echo "Checking filesystems:"
200	fsck -n -f | grep -v '^\*\* Phase'
201fi
202
203echo ""
204if checkyesno run_rdist && [ -f /etc/Distfile ]; then
205	echo "Running rdist:"
206	if [ -d /var/log/rdist ]; then
207		logf=`date +%Y.%b.%d`
208		rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
209	else
210		rdist -f /etc/Distfile 
211	fi
212fi
213
214if checkyesno run_security; then
215	SECOUT="$DAILYDIR/sec"
216	sh /etc/security 2>&1 > "$SECOUT"
217	if [ ! -s "$SECOUT" ]; then
218		echo "Nothing to report on $date" > "$SECOUT"
219	fi
220	mail -s "$host daily insecurity output for $date" $MAILTO < "$SECOUT"
221fi
222
223if checkyesno run_skeyaudit; then
224	echo ""
225	echo "Checking remaining s/key OTPs:"
226	skeyaudit
227fi
228
229if [ -f /etc/daily.local ]; then
230	echo ""
231	echo "Running /etc/daily.local:"
232	. /etc/daily.local
233fi
234