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