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