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