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