daily revision 1.58.2.2 1 1.58.2.2 tron #!/bin/sh -
2 1.58.2.2 tron #
3 1.58.2.2 tron # $NetBSD: daily,v 1.58.2.2 2004/05/30 07:22:09 tron Exp $
4 1.58.2.2 tron # @(#)daily 8.2 (Berkeley) 1/25/94
5 1.58.2.2 tron #
6 1.58.2.2 tron
7 1.58.2.2 tron export PATH=/bin:/usr/bin:/sbin:/usr/sbin
8 1.58.2.2 tron umask 077
9 1.58.2.2 tron
10 1.58.2.2 tron if [ -s /etc/daily.conf ]; then
11 1.58.2.2 tron . /etc/daily.conf
12 1.58.2.2 tron fi
13 1.58.2.2 tron
14 1.58.2.2 tron host=`hostname`
15 1.58.2.2 tron date=`date`
16 1.58.2.2 tron
17 1.58.2.2 tron echo "To: ${MAILTO:-root}"
18 1.58.2.2 tron echo "Subject: $host daily output for $date"
19 1.58.2.2 tron echo ""
20 1.58.2.2 tron
21 1.58.2.2 tron if [ -f /etc/rc.subr ]; then
22 1.58.2.2 tron . /etc/rc.subr
23 1.58.2.2 tron else
24 1.58.2.2 tron echo "Can't read /etc/rc.subr; aborting."
25 1.58.2.2 tron exit 1;
26 1.58.2.2 tron fi
27 1.58.2.2 tron
28 1.58.2.2 tron if [ -z "$MAILTO" -o "$USER" != "root" ]; then
29 1.58.2.2 tron MAILTO=root
30 1.58.2.2 tron fi
31 1.58.2.2 tron
32 1.58.2.2 tron echo ""
33 1.58.2.2 tron echo "Uptime: " `uptime`
34 1.58.2.2 tron
35 1.58.2.2 tron # Uncommenting any of the finds below would open up a race condition attack
36 1.58.2.2 tron # based on symlinks, potentially allowing removal of any file on the system.
37 1.58.2.2 tron #
38 1.58.2.2 tron #echo ""
39 1.58.2.2 tron #echo "Removing scratch and junk files:"
40 1.58.2.2 tron #if [ -d /tmp -a ! -h /tmp ]; then
41 1.58.2.2 tron # cd /tmp && {
42 1.58.2.2 tron # find . -type f -atime +3 -exec rm -f -- {} \;
43 1.58.2.2 tron # find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
44 1.58.2.2 tron # >/dev/null 2>&1; }
45 1.58.2.2 tron #fi
46 1.58.2.2 tron
47 1.58.2.2 tron #if [ -d /var/tmp -a ! -h /var/tmp ]; then
48 1.58.2.2 tron # cd /var/tmp && {
49 1.58.2.2 tron # find . ! -name . -atime +7 -exec rm -f -- {} \;
50 1.58.2.2 tron # find . ! \( -name . -o -name vi.recover \) -type d \
51 1.58.2.2 tron # -mtime +1 -exec rmdir -- {} \; \
52 1.58.2.2 tron # >/dev/null 2>&1; }
53 1.58.2.2 tron #fi
54 1.58.2.2 tron
55 1.58.2.2 tron # Additional junk directory cleanup would go like this:
56 1.58.2.2 tron #if [ -d /scratch -a ! -h /scratch ]; then
57 1.58.2.2 tron # cd /scratch && {
58 1.58.2.2 tron # find . ! -name . -atime +1 -exec rm -f -- {} \;
59 1.58.2.2 tron # find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
60 1.58.2.2 tron # >/dev/null 2>&1; }
61 1.58.2.2 tron #fi
62 1.58.2.2 tron
63 1.58.2.2 tron #if [ -d /var/rwho -a ! -h /var/rwho ] ; then
64 1.58.2.2 tron # cd /var/rwho && {
65 1.58.2.2 tron # find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
66 1.58.2.2 tron #fi
67 1.58.2.2 tron
68 1.58.2.2 tron DAILYDIR=`mktemp -d /tmp/_daily.XXXXXX` || exit 1
69 1.58.2.2 tron
70 1.58.2.2 tron trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
71 1.58.2.2 tron
72 1.58.2.2 tron if ! cd "$DAILYDIR"; then
73 1.58.2.2 tron echo "Can not cd to $DAILYDIR".
74 1.58.2.2 tron exit 1
75 1.58.2.2 tron fi
76 1.58.2.2 tron
77 1.58.2.2 tron TMP=daily.$$
78 1.58.2.2 tron TMP2=daily2.$$
79 1.58.2.2 tron
80 1.58.2.2 tron if checkyesno find_core; then
81 1.58.2.2 tron find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
82 1.58.2.2 tron -o -fstype null \
83 1.58.2.2 tron -o -fstype kernfs -o -fstype procfs \) -prune -o \
84 1.58.2.2 tron -name 'lost+found' -prune -o \
85 1.58.2.2 tron \( -name '*.core' -o -name 'core' \) -type f -print > $TMP
86 1.58.2.2 tron # \( -name '[#,]*' -o -name '.#*' -o -name a.out \
87 1.58.2.2 tron # -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
88 1.58.2.2 tron # -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
89 1.58.2.2 tron
90 1.58.2.2 tron egrep '\.core$|^core$' $TMP > $TMP2
91 1.58.2.2 tron if [ -s $TMP2 ]; then
92 1.58.2.2 tron echo ""
93 1.58.2.2 tron echo "Possible core dumps:"
94 1.58.2.2 tron cat $TMP2
95 1.58.2.2 tron fi
96 1.58.2.2 tron
97 1.58.2.2 tron # egrep -v '\.core' $TMP > $TMP2
98 1.58.2.2 tron # if [ -s $TMP2 ]; then
99 1.58.2.2 tron # echo ""
100 1.58.2.2 tron # echo "Deleted files:"
101 1.58.2.2 tron # cat $TMP2
102 1.58.2.2 tron # fi
103 1.58.2.2 tron
104 1.58.2.2 tron rm -f $TMP $TMP2
105 1.58.2.2 tron fi
106 1.58.2.2 tron
107 1.58.2.2 tron if checkyesno run_msgs; then
108 1.58.2.2 tron msgs -c
109 1.58.2.2 tron fi
110 1.58.2.2 tron
111 1.58.2.2 tron if checkyesno expire_news && [ -f /etc/news.expire ]; then
112 1.58.2.2 tron /etc/news.expire
113 1.58.2.2 tron fi
114 1.58.2.2 tron
115 1.58.2.2 tron if checkyesno purge_accounting && [ -f /var/account/acct ]; then
116 1.58.2.2 tron echo ""
117 1.58.2.2 tron echo "Purging accounting records:"
118 1.58.2.2 tron if [ -f /var/account/acct.0.gz ]; then
119 1.58.2.2 tron mv /var/account/acct.2.gz /var/account/acct.3.gz 2>/dev/null
120 1.58.2.2 tron mv /var/account/acct.1.gz /var/account/acct.2.gz 2>/dev/null
121 1.58.2.2 tron mv /var/account/acct.0.gz /var/account/acct.1.gz 2>/dev/null
122 1.58.2.2 tron else
123 1.58.2.2 tron mv /var/account/acct.2 /var/account/acct.3 2>/dev/null
124 1.58.2.2 tron mv /var/account/acct.1 /var/account/acct.2 2>/dev/null
125 1.58.2.2 tron mv /var/account/acct.0 /var/account/acct.1 2>/dev/null
126 1.58.2.2 tron fi
127 1.58.2.2 tron cp /var/account/acct /var/account/acct.0
128 1.58.2.2 tron sa -sq
129 1.58.2.2 tron if [ -f /var/account/acct.1.gz ]; then
130 1.58.2.2 tron gzip /var/account/acct.0
131 1.58.2.2 tron fi
132 1.58.2.2 tron fi
133 1.58.2.2 tron
134 1.58.2.2 tron if checkyesno run_calendar; then
135 1.58.2.2 tron calendar -a > $TMP 2>&1
136 1.58.2.2 tron if [ -s $TMP ]; then
137 1.58.2.2 tron echo ""
138 1.58.2.2 tron echo "Running calendar:"
139 1.58.2.2 tron cat $TMP
140 1.58.2.2 tron fi
141 1.58.2.2 tron rm -f $TMP
142 1.58.2.2 tron fi
143 1.58.2.2 tron
144 1.58.2.2 tron if checkyesno check_uucp && \
145 1.58.2.2 tron [ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then
146 1.58.2.2 tron echo ""
147 1.58.2.2 tron echo "Cleaning up UUCP:"
148 1.58.2.2 tron su daemon -c /usr/libexec/uucp/clean.daily
149 1.58.2.2 tron fi
150 1.58.2.2 tron
151 1.58.2.2 tron if checkyesno check_disks; then
152 1.58.2.2 tron if checkyesno show_remote_fs; then
153 1.58.2.2 tron df -hi -t nokernfs,procfs,null,fdesc > $TMP
154 1.58.2.2 tron else
155 1.58.2.2 tron df -hil -t nokernfs,procfs,null,fdesc > $TMP
156 1.58.2.2 tron fi
157 1.58.2.2 tron if [ -s /etc/dumpdates ] ; then
158 1.58.2.2 tron dump -W > $TMP2
159 1.58.2.2 tron fi
160 1.58.2.2 tron if [ -s $TMP -o -s $TMP2 ]; then
161 1.58.2.2 tron echo ""
162 1.58.2.2 tron echo "Checking subsystem status:"
163 1.58.2.2 tron echo ""
164 1.58.2.2 tron echo "disks:"
165 1.58.2.2 tron if [ -s $TMP ]; then
166 1.58.2.2 tron cat $TMP
167 1.58.2.2 tron echo ""
168 1.58.2.2 tron fi
169 1.58.2.2 tron if [ -s $TMP2 ]; then
170 1.58.2.2 tron cat $TMP2
171 1.58.2.2 tron echo ""
172 1.58.2.2 tron fi
173 1.58.2.2 tron echo ""
174 1.58.2.2 tron fi
175 1.58.2.2 tron rm -f $TMP $TMP2
176 1.58.2.2 tron touch $TMP2
177 1.58.2.2 tron for dev in `iostat -x | awk '/^raid/ { print $1 }'`; do
178 1.58.2.2 tron raidctl -s $dev | awk '/^.*: failed$/ {print $0}' > $TMP
179 1.58.2.2 tron if [ -s $TMP ]; then
180 1.58.2.2 tron echo "$dev:" >> $TMP2
181 1.58.2.2 tron cat $TMP >> $TMP2
182 1.58.2.2 tron fi
183 1.58.2.2 tron rm -f $TMP
184 1.58.2.2 tron done
185 1.58.2.2 tron if [ -s $TMP2 ]; then
186 1.58.2.2 tron echo "failed RAIDframe component(s):"
187 1.58.2.2 tron cat $TMP2
188 1.58.2.2 tron fi
189 1.58.2.2 tron rm -f $TMP2
190 1.58.2.2 tron fi
191 1.58.2.2 tron
192 1.58.2.2 tron if checkyesno check_mailq; then
193 1.58.2.2 tron mailq > $TMP
194 1.58.2.2 tron if ! grep -q "queue is empty$" $TMP; then
195 1.58.2.2 tron echo ""
196 1.58.2.2 tron echo "mail:"
197 1.58.2.2 tron cat $TMP
198 1.58.2.2 tron fi
199 1.58.2.2 tron fi
200 1.58.2.2 tron
201 1.58.2.2 tron rm -f $TMP
202 1.58.2.2 tron
203 1.58.2.2 tron if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
204 1.58.2.2 tron (cd /tmp; su -m uucp -c "uustat -a") > $TMP
205 1.58.2.2 tron if [ -s $TMP ]; then
206 1.58.2.2 tron echo ""
207 1.58.2.2 tron echo "uucp:"
208 1.58.2.2 tron cat $TMP
209 1.58.2.2 tron fi
210 1.58.2.2 tron fi
211 1.58.2.2 tron
212 1.58.2.2 tron rm -f $TMP
213 1.58.2.2 tron
214 1.58.2.2 tron if checkyesno check_network; then
215 1.58.2.2 tron echo ""
216 1.58.2.2 tron echo "network:"
217 1.58.2.2 tron if checkyesno full_netstat; then
218 1.58.2.2 tron netstat -inv
219 1.58.2.2 tron else
220 1.58.2.2 tron netstat -inv | awk 'BEGIN {
221 1.58.2.2 tron ifs[""] = 0;
222 1.58.2.2 tron }
223 1.58.2.2 tron /^[^\*]* / {
224 1.58.2.2 tron if (NR == 1) {
225 1.58.2.2 tron printf("%-8s %10s %6s %10s %6s %6s\n",
226 1.58.2.2 tron $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
227 1.58.2.2 tron next;
228 1.58.2.2 tron }
229 1.58.2.2 tron if (!($1 in ifs)) {
230 1.58.2.2 tron printf("%-8s %10d %6d %10d %6d %6d\n",
231 1.58.2.2 tron $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
232 1.58.2.2 tron ifs[$1] = 1;
233 1.58.2.2 tron }
234 1.58.2.2 tron }'
235 1.58.2.2 tron fi
236 1.58.2.2 tron echo ""
237 1.58.2.2 tron t=/var/rwho/*
238 1.58.2.2 tron if [ "$t" != '/var/rwho/*' ]; then
239 1.58.2.2 tron ruptime
240 1.58.2.2 tron fi
241 1.58.2.2 tron fi
242 1.58.2.2 tron
243 1.58.2.2 tron if checkyesno run_fsck; then
244 1.58.2.2 tron echo ""
245 1.58.2.2 tron echo "Checking filesystems:"
246 1.58.2.2 tron fsck -n -f | grep -v '^\*\* Phase'
247 1.58.2.2 tron fi
248 1.58.2.2 tron
249 1.58.2.2 tron echo ""
250 1.58.2.2 tron if checkyesno run_rdist && [ -f /etc/Distfile ]; then
251 1.58.2.2 tron echo "Running rdist:"
252 1.58.2.2 tron if [ -d /var/log/rdist ]; then
253 1.58.2.2 tron logf=`date +%Y.%b.%d`
254 1.58.2.2 tron rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
255 1.58.2.2 tron else
256 1.58.2.2 tron rdist -f /etc/Distfile
257 1.58.2.2 tron fi
258 1.58.2.2 tron fi
259 1.58.2.2 tron
260 1.58.2.2 tron if checkyesno run_security; then
261 1.58.2.2 tron SECOUT="$DAILYDIR/sec"
262 1.58.2.2 tron sh /etc/security > "$SECOUT" 2>&1
263 1.58.2.2 tron if [ ! -s "$SECOUT" ]; then
264 1.58.2.2 tron if checkyesno send_empty_security; then
265 1.58.2.2 tron echo "Nothing to report on $date" > "$SECOUT"
266 1.58.2.2 tron else
267 1.58.2.2 tron echo ""
268 1.58.2.2 tron echo "Suppressing empty security report."
269 1.58.2.2 tron fi
270 1.58.2.2 tron fi
271 1.58.2.2 tron if [ -s "$SECOUT" ]; then
272 1.58.2.2 tron mail -s "$host daily insecurity output for $date" \
273 1.58.2.2 tron $MAILTO < "$SECOUT"
274 1.58.2.2 tron fi
275 1.58.2.2 tron fi
276 1.58.2.2 tron
277 1.58.2.2 tron if checkyesno run_skeyaudit; then
278 1.58.2.2 tron if [ -s /etc/skeykeys ]; then
279 1.58.2.2 tron echo ""
280 1.58.2.2 tron echo "Checking remaining s/key OTPs:"
281 1.58.2.2 tron skeyaudit
282 1.58.2.2 tron fi
283 1.58.2.2 tron fi
284 1.58.2.2 tron
285 1.58.2.2 tron if [ -f /etc/daily.local ]; then
286 1.58.2.2 tron echo ""
287 1.58.2.2 tron echo "Running /etc/daily.local:"
288 1.58.2.2 tron . /etc/daily.local
289 1.58.2.2 tron fi
290