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