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