summaryrefslogtreecommitdiff
path: root/etc/daily
blob: 9c62d1675ee44d5037752fc30957b2ebb9bb11d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/sh -
#
#	$NetBSD: daily,v 1.57 2003/12/28 16:34:03 atatat Exp $
#	@(#)daily	8.2 (Berkeley) 1/25/94
#

export PATH=/bin:/usr/bin:/sbin:/usr/sbin
umask 077

if [ -s /etc/daily.conf ]; then
	. /etc/daily.conf
fi

host=`hostname`
date=`date`

echo "To: ${MAILTO:-root}"
echo "Subject: $host daily output for $date"
echo ""

if [ -f /etc/rc.subr ]; then
	. /etc/rc.subr
else
	echo "Can't read /etc/rc.subr; aborting."
	exit 1;
fi

if [ -z "$MAILTO" -o "$USER" != "root" ]; then
	MAILTO=root
fi

echo ""
echo "Uptime: " `uptime`

# Uncommenting any of the finds below would open up a race condition attack
# based on symlinks, potentially allowing removal of any file on the system.
#
#echo ""
#echo "Removing scratch and junk files:"
#if [ -d /tmp -a ! -h /tmp ]; then
#	cd /tmp && {
#	find . -type f -atime +3 -exec rm -f -- {} \;
#	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
#	    >/dev/null 2>&1; }
#fi

#if [ -d /var/tmp -a ! -h /var/tmp ]; then
#	cd /var/tmp && {
#	find . ! -name . -atime +7 -exec rm -f -- {} \;
#	find . ! \( -name . -o -name vi.recover \) -type d \
#		-mtime +1 -exec rmdir -- {} \; \
#	    >/dev/null 2>&1; }
#fi

# Additional junk directory cleanup would go like this:
#if [ -d /scratch -a ! -h /scratch ]; then
#	cd /scratch && {
#	find . ! -name . -atime +1 -exec rm -f -- {} \;
#	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
#	    >/dev/null 2>&1; }
#fi

#if [ -d /var/rwho -a ! -h /var/rwho ] ; then
#	cd /var/rwho && {
#	find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
#fi

DAILYDIR=`mktemp -d /tmp/_daily.XXXXXX` || exit 1

trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT

if ! cd "$DAILYDIR"; then
	echo "Can not cd to $DAILYDIR".
	exit 1
fi

TMP=daily.$$
TMP2=daily2.$$

if checkyesno find_core; then
	find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
		-o -fstype null \
		-o -fstype kernfs -o -fstype procfs \) -prune -o \
		-name 'lost+found' -prune -o \
		\( -name '*.core' -o -name 'core' \) -type f -print > $TMP
#		\( -name '[#,]*' -o -name '.#*' -o -name a.out \
#		   -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
#			-a -atime +3 -exec rm -f -- {} \; -a -print > $TMP

	egrep '\.core$|^core$' $TMP > $TMP2
	if [ -s $TMP2 ]; then
		echo ""
		echo "Possible core dumps:"
		cat $TMP2
	fi

#	egrep -v '\.core' $TMP > $TMP2
#	if [ -s $TMP2 ]; then
#		echo ""
#		echo "Deleted files:"
#		cat $TMP2
#	fi

	rm -f $TMP $TMP2
fi

if checkyesno run_msgs; then
	msgs -c
fi

if checkyesno expire_news && [ -f /etc/news.expire ]; then
	/etc/news.expire
fi

if checkyesno purge_accounting && [ -f /var/account/acct ]; then
	echo ""
	echo "Purging accounting records:"
	mv /var/account/acct.2 /var/account/acct.3 2>/dev/null
	mv /var/account/acct.1 /var/account/acct.2 2>/dev/null
	mv /var/account/acct.0 /var/account/acct.1 2>/dev/null
	cp /var/account/acct /var/account/acct.0
	sa -sq
fi

if checkyesno run_calendar; then
	calendar -a > $TMP 2>&1
	if [ -s $TMP ]; then
		echo ""
		echo "Running calendar:"
		cat $TMP
	fi
	rm -f $TMP
fi

if checkyesno check_uucp && \
    [ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then
	echo ""
	echo "Cleaning up UUCP:"
	su daemon -c /usr/libexec/uucp/clean.daily
fi

if checkyesno check_disks; then
	if checkyesno show_remote_fs; then
		df -hi -t nokernfs,procfs,null,fdesc > $TMP
	else
		df -hil -t nokernfs,procfs,null,fdesc > $TMP
	fi
	if [ -s /etc/dumpdates ] ; then
		dump -W > $TMP2
	fi
	if [ -s $TMP -o -s $TMP2 ]; then
		echo ""
		echo "Checking subsystem status:"
		echo ""
		echo "disks:"
		if [ -s $TMP ]; then
			cat $TMP
			echo ""
		fi
		if [ -s $TMP2 ]; then
			cat $TMP2
			echo ""
		fi
		echo ""
	fi
	rm -f $TMP $TMP2
	touch $TMP2
	for dev in `iostat -x | awk '/^raid/ { print $1 }'`; do
		raidctl -s $dev | awk '/^.*: failed$/ {print $0}' > $TMP
		if [ -s $TMP ]; then
			echo "$dev:" >> $TMP2
			cat $TMP >> $TMP2
		fi
		rm -f $TMP
	done
	if [ -s $TMP2 ]; then
		echo "failed RAIDframe component(s):"
			cat $TMP2
	fi
	rm -f $TMP2
fi

if checkyesno check_mailq; then
	mailq > $TMP
	if ! grep -q "queue is empty$" $TMP; then
		echo ""
		echo "mail:"
		cat $TMP
	fi
fi

rm -f $TMP

if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
	(cd /tmp; su -m uucp -c "uustat -a") > $TMP
	if [ -s $TMP ]; then
		echo ""
		echo "uucp:"
		cat $TMP
	fi
fi

rm -f $TMP

if checkyesno check_network; then
	echo ""
	echo "network:"
	if checkyesno full_netstat; then
		netstat -inv
	else
		netstat -in | awk 'BEGIN {
			ifs[""] = 0;
		}
		/^[^\*]* / {
			if (NR == 1) {
				printf("%-8s %10s %6s %10s %6s %6s\n",
				  $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
				next;
			}
			if (!($1 in ifs)) {
				printf("%-8s %10d %6d %10d %6d %6d\n",
				  $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
				ifs[$1] = 1;
			}
		}'
	fi
	echo ""
	t=/var/rwho/*
	if [ "$t" != '/var/rwho/*' ]; then
		ruptime
	fi
fi

if checkyesno run_fsck; then
	echo ""
	echo "Checking filesystems:"
	fsck -n -f | grep -v '^\*\* Phase'
fi

echo ""
if checkyesno run_rdist && [ -f /etc/Distfile ]; then
	echo "Running rdist:"
	if [ -d /var/log/rdist ]; then
		logf=`date +%Y.%b.%d`
		rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
	else
		rdist -f /etc/Distfile 
	fi
fi

if checkyesno run_security; then
	SECOUT="$DAILYDIR/sec"
	sh /etc/security > "$SECOUT" 2>&1
	if [ ! -s "$SECOUT" ]; then
		if checkyesno send_empty_security; then
			echo "Nothing to report on $date" > "$SECOUT"
		else
			echo ""
			echo "Suppressing empty security report."
		fi
	fi
	if [ -s "$SECOUT" ]; then
		mail -s "$host daily insecurity output for $date" \
		    $MAILTO < "$SECOUT"
	fi
fi

if checkyesno run_skeyaudit; then
	if [ -s /etc/skeykeys ]; then
		echo ""
		echo "Checking remaining s/key OTPs:"
		skeyaudit
	fi
fi

if [ -f /etc/daily.local ]; then
	echo ""
	echo "Running /etc/daily.local:"
	. /etc/daily.local
fi