daily revision 1.37
1#!/bin/sh - 2# 3# $NetBSD: daily,v 1.37 2001/08/09 15:30:30 lukem 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 kernfs -o -fstype procfs \) -a -prune -o \ 83 -name 'lost+found' -a -prune -o \ 84 \( -name '*.core' -o -name 'core' \) -a -print > $TMP 85# \( -name '[#,]*' -o -name '.#*' -o -name a.out \ 86# -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \ 87# -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP 88 89 egrep '\.core$|^core$' $TMP > $TMP2 90 if [ -s $TMP2 ]; then 91 echo "" 92 echo "Possible core dumps:" 93 cat $TMP2 94 fi 95 96# egrep -v '\.core' $TMP > $TMP2 97# if [ -s $TMP2 ]; then 98# echo "" 99# echo "Deleted files:" 100# cat $TMP2 101# fi 102 103 rm -f $TMP $TMP2 104fi 105 106if checkyesno run_msgs; then 107 msgs -c 108fi 109 110if checkyesno expire_news && [ -f /etc/news.expire ]; then 111 /etc/news.expire 112fi 113 114if checkyesno purge_accounting && [ -f /var/account/acct ]; then 115 echo "" 116 echo "Purging accounting records:" 117 mv /var/account/acct.2 /var/account/acct.3 118 mv /var/account/acct.1 /var/account/acct.2 119 mv /var/account/acct.0 /var/account/acct.1 120 cp /var/account/acct /var/account/acct.0 121 sa -sq 122fi 123 124if checkyesno run_calendar; then 125 calendar -a > $TMP 126 if [ -s $TMP ]; then 127 echo "" 128 echo "Running calendar:" 129 cat $TMP 130 fi 131 rm -f $TMP 132fi 133 134if checkyesno check_uucp && \ 135 [ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then 136 echo "" 137 echo "Cleaning up UUCP:" 138 su daemon -c /usr/libexec/uucp/clean.daily 139fi 140 141if checkyesno check_disks; then 142 df -k > $TMP 143 dump W > $TMP2 144 if [ -s $TMP -o -s $TMP2 ]; then 145 echo "" 146 echo "Checking subsystem status:" 147 echo "" 148 echo "disks:" 149 if [ -s $TMP ]; then 150 cat $TMP 151 echo "" 152 fi 153 if [ -s $TMP2 ]; then 154 cat $TMP2 155 echo "" 156 fi 157 echo "" 158 fi 159fi 160 161rm -f $TMP $TMP2 162 163if checkyesno check_mailq; then 164 mailq > $TMP 165 if ! grep -q "^Mail queue is empty$" $TMP; then 166 echo "" 167 echo "mail:" 168 cat $TMP 169 fi 170fi 171 172rm -f $TMP 173 174if checkyesno check_uucp && [ -d /var/spool/uucp ]; then 175 uustat -a > $TMP 176 if [ -s $TMP ]; then 177 echo "" 178 echo "uucp:" 179 cat $TMP 180 fi 181fi 182 183rm -f $TMP 184 185if checkyesno check_network; then 186 echo "" 187 echo "network:" 188 netstat -inv 189 echo "" 190 t=/var/rwho/* 191 if [ "$t" != '/var/rwho/*' ]; then 192 ruptime 193 fi 194fi 195 196if checkyesno run_fsck; then 197 echo "" 198 echo "Checking filesystems:" 199 fsck -n -f | grep -v '^\*\* Phase' 200fi 201 202echo "" 203if checkyesno run_rdist && [ -f /etc/Distfile ]; then 204 echo "Running rdist:" 205 if [ -d /var/log/rdist ]; then 206 logf=`date +%Y.%b.%d` 207 rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf 208 else 209 rdist -f /etc/Distfile 210 fi 211fi 212 213if checkyesno run_security; then 214 SECOUT="$DAILYDIR/sec" 215 sh /etc/security 2>&1 > "$SECOUT" 216 if [ ! -s "$SECOUT" ]; then 217 echo "Nothing to report on $date" > "$SECOUT" 218 fi 219 mail -s "$host daily insecurity output for $date" $MAILTO < "$SECOUT" 220fi 221 222if checkyesno run_skeyaudit; then 223 echo "" 224 echo "Checking remaining s/key OTPs:" 225 skeyaudit 226fi 227 228if [ -f /etc/daily.local ]; then 229 echo "" 230 echo "Running /etc/daily.local:" 231 . /etc/daily.local 232fi 233