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