Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / etc / daily
blob8c2fca42521d68f7e844da4ca809bec83754275b
1 #!/bin/sh -
3 # $NetBSD: daily,v 1.71 2008/08/30 10:53:22 bouyer Exp $
4 # @(#)daily 8.2 (Berkeley) 1/25/94
7 export PATH=/bin:/usr/bin:/sbin:/usr/sbin
8 umask 077
10 if [ -s /etc/daily.conf ]; then
11 . /etc/daily.conf
14 host=`hostname`
15 date=`date`
16 rcvar_manpage='daily.conf(5)'
18 echo "To: ${MAILTO:-root}"
19 echo "Subject: $host daily output for $date"
20 echo ""
22 if [ -f /etc/rc.subr ]; then
23 . /etc/rc.subr
24 else
25 echo "Can't read /etc/rc.subr; aborting."
26 exit 1;
29 if [ -z "$MAILTO" -o "$USER" != "root" ]; then
30 MAILTO=root
33 echo ""
34 echo "Uptime: " `uptime`
36 # Uncommenting any of the finds below would open up a race condition attack
37 # based on symlinks, potentially allowing removal of any file on the system.
39 #echo ""
40 #echo "Removing scratch and junk files:"
41 #if [ -d /tmp -a ! -h /tmp ]; then
42 # cd /tmp && {
43 # find . -type f -atime +3 -exec rm -f -- {} \;
44 # find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
45 # >/dev/null 2>&1; }
46 #fi
48 #if [ -d /var/tmp -a ! -h /var/tmp ]; then
49 # cd /var/tmp && {
50 # find . ! -name . -atime +7 -exec rm -f -- {} \;
51 # find . ! \( -name . -o -name vi.recover \) -type d \
52 # -mtime +1 -exec rmdir -- {} \; \
53 # >/dev/null 2>&1; }
54 #fi
56 # Additional junk directory cleanup would go like this:
57 #if [ -d /scratch -a ! -h /scratch ]; then
58 # cd /scratch && {
59 # find . ! -name . -atime +1 -exec rm -f -- {} \;
60 # find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
61 # >/dev/null 2>&1; }
62 #fi
64 #if [ -d /var/rwho -a ! -h /var/rwho ] ; then
65 # cd /var/rwho && {
66 # find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
67 #fi
69 DAILYDIR=$(mktemp -d -t _daily) || exit 1
71 trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
73 if ! cd "$DAILYDIR"; then
74 echo "Can not cd to $DAILYDIR".
75 exit 1
78 TMP=daily.$$
79 TMP2=daily2.$$
81 if checkyesno find_core; then
82 # Turn "foo !bar bax" into "-fstype foo -o ! -fstype bar -o -fstype bax"
83 ignfstypes=`echo $find_core_ignore_fstypes | \
84 sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' \
85 -e's/^-o //'`
86 find / \( $ignfstypes \) -prune -o \
87 -name 'lost+found' -prune -o \
88 \( -name '*.core' -o -name 'core' \) -type f -print > $TMP
89 # \( -name '[#,]*' -o -name '.#*' -o -name a.out \
90 # -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
91 # -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
93 egrep '\.core$|^core$' $TMP > $TMP2
94 if [ -s $TMP2 ]; then
95 echo ""
96 echo "Possible core dumps:"
97 cat $TMP2
100 # egrep -v '\.core' $TMP > $TMP2
101 # if [ -s $TMP2 ]; then
102 # echo ""
103 # echo "Deleted files:"
104 # cat $TMP2
105 # fi
107 rm -f $TMP $TMP2
110 if checkyesno run_msgs; then
111 msgs -c
114 if checkyesno expire_news && [ -f /etc/news.expire ]; then
115 /etc/news.expire
118 if checkyesno purge_accounting && [ -f /var/account/acct ]; then
119 echo ""
120 echo "Purging accounting records:"
121 if [ -f /var/account/acct.0.gz ]; then
122 mv /var/account/acct.2.gz /var/account/acct.3.gz 2>/dev/null
123 mv /var/account/acct.1.gz /var/account/acct.2.gz 2>/dev/null
124 mv /var/account/acct.0.gz /var/account/acct.1.gz 2>/dev/null
125 else
126 mv /var/account/acct.2 /var/account/acct.3 2>/dev/null
127 mv /var/account/acct.1 /var/account/acct.2 2>/dev/null
128 mv /var/account/acct.0 /var/account/acct.1 2>/dev/null
130 cp /var/account/acct /var/account/acct.0
131 sa -sq
132 if [ -f /var/account/acct.1.gz ]; then
133 gzip /var/account/acct.0
137 if checkyesno run_calendar; then
138 calendar -a > $TMP 2>&1
139 if [ -s $TMP ]; then
140 echo ""
141 echo "Running calendar:"
142 cat $TMP
144 rm -f $TMP
147 if checkyesno check_disks; then
148 if checkyesno show_remote_fs; then
149 df -hi -t nokernfs,procfs,ptyfs,null,fdesc > $TMP
150 else
151 df -hil -t nokernfs,procfs,ptyfs,null,fdesc > $TMP
153 if [ -s /etc/dumpdates ] ; then
154 dump -W > $TMP2
156 if [ -s $TMP -o -s $TMP2 ]; then
157 echo ""
158 echo "Checking subsystem status:"
159 echo ""
160 echo "disks:"
161 if [ -s $TMP ]; then
162 cat $TMP | sed 's/Mounted on/Mount/'
163 echo ""
165 if [ -s $TMP2 ]; then
166 cat $TMP2
167 echo ""
169 echo ""
171 rm -f $TMP $TMP2
172 touch $TMP2
173 for dev in `iostat -x | awk '/^raid/ { print $1 }'`; do
174 raidctl -s $dev | awk '/^.*: failed$/ {print $0}' > $TMP
175 if [ -s $TMP ]; then
176 echo "$dev:" >> $TMP2
177 cat $TMP >> $TMP2
179 rm -f $TMP
180 done
181 if [ -s $TMP2 ]; then
182 echo "failed RAIDframe component(s):"
183 cat $TMP2
185 rm -f $TMP2
188 if checkyesno check_mailq; then
189 mailq > $TMP
190 if ! grep -q "queue is empty$" $TMP; then
191 echo ""
192 echo "mail:"
193 cat $TMP
197 rm -f $TMP
199 if checkyesno check_network; then
200 echo ""
201 echo "network:"
202 if checkyesno full_netstat; then
203 netstat -inv
204 else
205 netstat -inv | awk 'BEGIN {
206 ifs[""] = 0;
208 /^[^\*]* / {
209 if (NR == 1) {
210 printf("%-8s %12s %6s %12s %6s %6s\n",
211 $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
212 next;
214 if (!($1 in ifs)) {
215 printf("%-8s %12s %6s %12s %6s %6s\n",
216 $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
217 ifs[$1] = 1;
221 echo ""
222 t=/var/rwho/*
223 if [ "$t" != '/var/rwho/*' ]; then
224 ruptime
228 if checkyesno run_fsck; then
229 echo ""
230 echo "Checking filesystems:"
231 fsck -n -f ${run_fsck_flags} | grep -v '^\*\* Phase'
234 echo ""
235 if checkyesno run_rdist && [ -f /etc/Distfile ]; then
236 echo "Running rdist:"
237 if [ -d /var/log/rdist ]; then
238 logf=`date +%Y.%b.%d`
239 rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
240 else
241 rdist -f /etc/Distfile
245 if checkyesno run_security; then
246 SECOUT="$DAILYDIR/sec"
247 sh /etc/security > "$SECOUT" 2>&1
248 if [ ! -s "$SECOUT" ]; then
249 if checkyesno send_empty_security; then
250 echo "Nothing to report on $date" > "$SECOUT"
251 else
252 echo ""
253 echo "Suppressing empty security report."
256 if [ -s "$SECOUT" ]; then
257 mail -s "$host daily insecurity output for $date" \
258 "$MAILTO" < "$SECOUT"
262 if checkyesno run_skeyaudit; then
263 if [ -s /etc/skeykeys ]; then
264 echo ""
265 echo "Checking remaining s/key OTPs:"
266 skeyaudit
270 if [ -f /etc/daily.local ]; then
271 ( . /etc/daily.local ) > $TMP 2>&1
272 if [ -s $TMP ] ; then
273 printf "\nRunning /etc/daily.local:\n"
274 cat $TMP
276 rm -f $TMP