daily revision 1.52
1#!/bin/sh -
2#
3#	$NetBSD: daily,v 1.52 2003/12/07 16:35:04 perry 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 \) -prune -o \
84		-name 'lost+found' -prune -o \
85		\( -name '*.core' -o -name 'core' \) -type f -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 2>/dev/null
119	mv /var/account/acct.1 /var/account/acct.2 2>/dev/null
120	mv /var/account/acct.0 /var/account/acct.1 2>/dev/null
121	cp /var/account/acct /var/account/acct.0
122	sa -sq
123fi
124
125if checkyesno run_calendar; then
126	calendar -a > $TMP 2>&1
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 -hi > $TMP 
144	if [ -s /etc/dumpdates ] ; then
145		dump -W > $TMP2
146	fi
147	if [ -s $TMP -o -s $TMP2 ]; then
148		echo ""
149		echo "Checking subsystem status:"
150		echo ""
151		echo "disks:"
152		if [ -s $TMP ]; then
153			cat $TMP
154			echo ""
155		fi
156		if [ -s $TMP2 ]; then
157			cat $TMP2
158			echo ""
159		fi
160		echo ""
161	fi
162	rm -f $TMP $TMP2
163	touch $TMP2
164	for dev in `iostat -x | awk '/^raid/ { print $1 }'`; do
165		raidctl -s $dev | awk '/^.*: failed$/ {print $0}' > $TMP
166		if [ -s $TMP ]; then
167			echo "$dev:" >> $TMP2
168			cat $TMP >> $TMP2
169		fi
170		rm -f $TMP
171	done
172	if [ -s $TMP2 ]; then
173		echo "failed RAIDframe component(s):"
174			cat $TMP2
175	fi
176	rm -f $TMP2
177fi
178
179if checkyesno check_mailq; then
180	mailq > $TMP
181	if ! grep -q "queue is empty$" $TMP; then
182		echo ""
183		echo "mail:"
184		cat $TMP
185	fi
186fi
187
188rm -f $TMP
189
190if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
191	(cd /tmp; su -m uucp -c "uustat -a") > $TMP
192	if [ -s $TMP ]; then
193		echo ""
194		echo "uucp:"
195		cat $TMP
196	fi
197fi
198
199rm -f $TMP
200
201if checkyesno check_network; then
202	echo ""
203	echo "network:"
204	netstat -inv
205	echo ""
206	t=/var/rwho/*
207	if [ "$t" != '/var/rwho/*' ]; then
208		ruptime
209	fi
210fi
211
212if checkyesno run_fsck; then
213	echo ""
214	echo "Checking filesystems:"
215	fsck -n -f | grep -v '^\*\* Phase'
216fi
217
218echo ""
219if checkyesno run_rdist && [ -f /etc/Distfile ]; then
220	echo "Running rdist:"
221	if [ -d /var/log/rdist ]; then
222		logf=`date +%Y.%b.%d`
223		rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
224	else
225		rdist -f /etc/Distfile 
226	fi
227fi
228
229if checkyesno run_security; then
230	SECOUT="$DAILYDIR/sec"
231	sh /etc/security > "$SECOUT" 2>&1
232	if [ ! -s "$SECOUT" ]; then
233		if checkyesno send_empty_security; then
234			echo "Nothing to report on $date" > "$SECOUT"
235		else
236			echo ""
237			echo "Supressing empty security report."
238		fi
239	fi
240	if [ -s "$SECOUT" ]; then
241		mail -s "$host daily insecurity output for $date" \
242		    $MAILTO < "$SECOUT"
243	fi
244fi
245
246if checkyesno run_skeyaudit; then
247	if [ -s /etc/skeykeys ]; then
248		echo ""
249		echo "Checking remaining s/key OTPs:"
250		skeyaudit
251	fi
252fi
253
254if [ -f /etc/daily.local ]; then
255	echo ""
256	echo "Running /etc/daily.local:"
257	. /etc/daily.local
258fi
259