daily revision 1.35
1#!/bin/sh -
2#
3#	$NetBSD: daily,v 1.35 2001/04/22 20:34:48 aymeric 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
68TMPDIR=/tmp/_daily.$$
69
70if ! mkdir $TMPDIR; then
71	echo can not create $TMPDIR.
72	exit 1
73fi
74
75if ! cd $TMPDIR; then
76	echo can not cd to $TMPDIR.
77	exit 1
78fi
79
80TMP=daily.$$
81TMP2=daily2.$$
82
83if checkyesno find_core; then
84	find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
85		-o -fstype kernfs -o -fstype procfs \) -a -prune -o \
86		-name 'lost+found' -a -prune -o \
87		\( -name '*.core' -o -name 'core' \) -a -print > $TMP
88#		\( -name '[#,]*' -o -name '.#*' -o -name a.out \
89#		   -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
90#			-a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
91
92	egrep '\.core$|^core$' $TMP > $TMP2
93	if [ -s $TMP2 ]; then
94		echo ""
95		echo "Possible core dumps:"
96		cat $TMP2
97	fi
98
99#	egrep -v '\.core' $TMP > $TMP2
100#	if [ -s $TMP2 ]; then
101#		echo ""
102#		echo "Deleted files:"
103#		cat $TMP2
104#	fi
105
106	rm -f $TMP $TMP2
107fi
108
109if checkyesno run_msgs; then
110	msgs -c
111fi
112
113if checkyesno expire_news && [ -f /etc/news.expire ]; then
114	/etc/news.expire
115fi
116
117if checkyesno purge_accounting && [ -f /var/account/acct ]; then
118	echo ""
119	echo "Purging accounting records:"
120	mv /var/account/acct.2 /var/account/acct.3
121	mv /var/account/acct.1 /var/account/acct.2
122	mv /var/account/acct.0 /var/account/acct.1
123	cp /var/account/acct /var/account/acct.0
124	sa -sq
125fi
126
127if checkyesno run_calendar; then
128	calendar -a > $TMP
129	if [ -s $TMP ]; then
130		echo ""
131		echo "Running calendar:"
132		cat $TMP
133	fi
134	rm -f $TMP
135fi
136
137if checkyesno check_uucp && \
138    [ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then
139	echo ""
140	echo "Cleaning up UUCP:"
141	su daemon -c /usr/libexec/uucp/clean.daily
142fi
143
144if checkyesno check_disks; then
145	df -k > $TMP 
146	dump W > $TMP2
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
162fi
163
164rm -f $TMP $TMP2
165
166if checkyesno check_mailq; then
167	mailq > $TMP
168	if ! grep -q "^Mail queue is empty$" $TMP; then
169		echo ""
170		echo "mail:"
171		cat $TMP
172	fi
173fi
174
175rm -f $TMP
176
177if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
178	uustat -a > $TMP
179	if [ -s $TMP ]; then
180		echo ""
181		echo "uucp:"
182		cat $TMP
183	fi
184fi
185
186rm -f $TMP
187
188if checkyesno check_network; then
189	echo ""
190	echo "network:"
191	netstat -inv
192	echo ""
193	t=/var/rwho/*
194	if [ "$t" != '/var/rwho/*' ]; then
195		ruptime
196	fi
197fi
198
199if checkyesno run_fsck; then
200	echo ""
201	echo "Checking filesystems:"
202	fsck -n | grep -v '^\*\* Phase'
203fi
204
205echo ""
206if checkyesno run_rdist && [ -f /etc/Distfile ]; then
207	echo "Running rdist:"
208	if [ -d /var/log/rdist ]; then
209		logf=`date +%Y.%b.%d`
210		rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
211	else
212		rdist -f /etc/Distfile 
213	fi
214fi
215
216if checkyesno run_security; then
217	SECOUT=$TMPDIR/sec
218	sh /etc/security 2>&1 > $SECOUT
219	if [ ! -s $SECOUT ]; then
220		echo "Nothing to report on $date" > $SECOUT
221	fi
222	mail -s "$host daily insecurity output for $date" $MAILTO < $SECOUT
223fi
224
225if checkyesno run_skeyaudit; then
226	echo ""
227	echo "Checking remaining s/key OTPs:"
228	skeyaudit
229fi
230
231if [ -f /etc/daily.local ]; then
232	echo ""
233	echo "Running /etc/daily.local:"
234	. /etc/daily.local
235fi
236
237rm -rf $TMPDIR
238