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