1#!/bin/sh - 2# 3# @(#)daily 5.19 (Berkeley) 09/01/92 4# 5PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin 6host=`hostname` 7echo "Subject: $host daily run output" 8bak=/var/backups 9 10echo "" 11echo "Removing scratch and junk files:" 12if [ -d /tmp ]; then 13 cd /tmp && { 14 find . -type f -atime +3 -exec rm -f -- {} \; 15 find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \ 16 >/dev/null 2>&1; } 17fi 18 19if [ -d /var/tmp -a "X$CLEANVARTMP" = X1 ]; then 20 cd /var/tmp && { 21 find . ! -name . -atime +7 -exec rm -f -- {} \; 22 find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \ 23 >/dev/null 2>&1; } 24fi 25 26if [ -d /scratch ]; then 27 cd /scratch && { 28 find . ! -name . -atime +1 -exec rm -f -- {} \; 29 find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \ 30 >/dev/null 2>&1; } 31fi 32 33if [ -d /var/preserve ]; then 34 cd /var/preserve && { 35 find . ! -name . -mtime +7 -exec rm -f -- {} \; ; } 36fi 37 38if [ -d /var/rwho ] ; then 39 cd /var/rwho && { 40 find . ! -name . -mtime +7 -exec rm -f -- {} \; ; } 41fi 42 43cd /tmp 44TMP=daily.$$ 45find / \( ! -fstype local -o -fstype rdonly \) -a -prune -o \ 46 -name 'core.*' -a -print -o \ 47 \( -name '[#,]*' -o -name '.#*' -o -name a.out \ 48 -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \ 49 -a -atime +3 -a -exec rm -f -- {} \; -a -print > $TMP 50echo "" 51echo "Possible core dumps:" 52egrep 'core\.' $TMP | sed '/core.[05cho]$/d' 53 54echo "" 55echo "Deleted files:" 56egrep -v 'core\.' $TMP 57 58rm -f $TMP 59 60msgs -c 61if [ -f /etc/news.expire ]; then 62 /etc/news.expire 63fi 64 65echo "" 66echo "Purging accounting records:" 67mv /var/account/acct.2 /var/account/acct.3 68mv /var/account/acct.1 /var/account/acct.2 69mv /var/account/acct.0 /var/account/acct.1 70cp /var/account/acct /var/account/acct.0 71sa -s > /dev/null 72 73# If ROOTBACKUP is set to 1 in the environment, and 74# if filesystem named /altroot is type ufs, on /dev/* and mounted "xx", 75# use it as a backup root filesystem to be updated daily. 76[ "X$ROOTBACKUP" = X1 ] && { 77 rootdev=`awk '$2 == "/" && $1 ~ /^\/dev\// && $3 == "ufs" && \ 78 $4 == "rw" \ 79 { print substr($1, 6) }' < /etc/fstab` 80 rootbak=`awk '$2 == "/altroot" && $1 ~ /^\/dev\// && $3 == "ufs" && \ 81 $4 == "xx" \ 82 { print substr($1, 6) }' < /etc/fstab` 83 [ X$rootdev != X -a X$rootbak != X ] && { 84 sync 85 echo "" 86 echo "Backing up root filesystem:" 87 echo "copying /dev/r$rootdev to /dev/r$rootbak" 88 dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \ 89 conv=noerror,sync 90 fsck -y /dev/r$rootbak 91 } 92} 93 94echo "" 95echo "Running calendar:" 96calendar -a 97 98echo "" 99echo "Rotating mail log:" 100cd /var/log 101rm -f maillog.7 102if [ -f maillog.6 ]; then mv -f maillog.6 maillog.7; fi 103if [ -f maillog.5 ]; then mv -f maillog.5 maillog.6; fi 104if [ -f maillog.4 ]; then mv -f maillog.4 maillog.5; fi 105if [ -f maillog.3 ]; then mv -f maillog.3 maillog.4; fi 106if [ -f maillog.2 ]; then mv -f maillog.2 maillog.3; fi 107if [ -f maillog.1 ]; then mv -f maillog.1 maillog.2; fi 108if [ -f maillog.0 ]; then mv -f maillog.0 maillog.1; fi 109mv -f maillog maillog.0 110cp /dev/null maillog 111chmod 644 maillog 112kill -1 `cat /var/run/syslog.pid` 113cd / 114 115if [ -d /var/spool/uucp -a -f /etc/uuclean.daily ]; then 116 echo "" 117 echo "Cleaning up UUCP:" 118 echo /etc/uuclean.daily | su daemon 119fi 120 121echo "" 122echo "" 123echo "Checking subsystem status:" 124echo "" 125echo "disks:" 126env BLOCKSIZE=1k df 127echo "" 128dump W 129echo "" 130 131 132echo "" 133echo "mail:" 134mailq 135 136if [ -d /var/spool/uucp ]; then 137 echo "" 138 echo "uucp:" 139 uusnap 140fi 141 142echo "" 143echo "network:" 144netstat -i 145echo "" 146ruptime 147 148echo "" 149echo "Checking filesystems:" 150fsck -n | grep -v '^\*\* Phase' 151 152echo "" 153if [ -f /etc/Distfile ]; then 154 echo "Running rdist:" 155 if [ -d /var/log/rdist ]; then 156 logf=`date | awk '{printf "%s.%s.%s", $6, $2, $3}'` 157 rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf 158 else 159 rdist -f /etc/Distfile 160 fi 161fi 162 163sh /etc/security 2>&1 | mail -s "$host daily insecurity output" root 164