daily revision 1.4
1#!/bin/sh - 2# 3# @(#)daily 5.12 (Berkeley) 5/24/91 4# 5PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local 6host=`hostname -s` 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 ]; 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 44find / ! -fstype local -a -prune -o \ 45 \( -name '[#,]*' -o -name '.#*' -o -name a.out -o -name core \ 46 -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \ 47 -a -atime +3 -exec rm -f -- {} \; 48#msgs -c 49if [ -f /etc/news.expire ]; then 50 /etc/news.expire 51fi 52 53if [ -f /var/account ]; then 54 echo "" ; 55 echo "Purging accounting records:" ; 56 mv /var/account/acct.2 /var/account/acct.3 ; 57 mv /var/account/acct.1 /var/account/acct.2 ; 58 mv /var/account/acct.0 /var/account/acct.1 ; 59 cp /var/account/acct /var/account/acct.0 ; 60 sa -s > /dev/null ; 61fi 62 63echo "" 64echo "Backup passwd and group files:" 65if cmp -s $bak/master.passwd.bak /etc/master.passwd; then :; else 66 echo "$host passwd diffs:" 67 diff $bak/master.passwd.bak /etc/master.passwd 68 mv $bak/master.passwd.bak $bak/master.passwd.bak2 69 cp -p /etc/master.passwd $bak/master.passwd.bak 70fi 71if cmp -s $bak/group.bak /etc/group; then :; else 72 mv $bak/group.bak $bak/group.bak2 73 cp -p /etc/group $bak/group.bak 74fi 75if cmp -s $bak/aliases.bak /etc/aliases; then :; else 76 mv $bak/aliases.bak $bak/aliases.bak2 77 cp -p /etc/aliases $bak/aliases.bak 78fi 79if [ -f /etc/Distfile ]; then 80 if cmp -s $bak/Distfile.bak /etc/Distfile; then :; else 81 mv $bak/Distfile.bak $bak/Distfile.bak2 82 cp /etc/Distfile $bak/Distfile.bak 83 fi 84fi 85 86echo "" 87echo "Running calendar:" 88calendar -a 89 90echo "" 91echo "Making 'whatis' database:" 92if [ -d /usr/share/man -a -f /usr/share/man/makewhatis.sed ]; then 93 for file in `find /usr/share/man -type f -name '*.0' -print`; do \ 94 sed -n -f /usr/share/man/makewhatis.sed $file; \ 95 done | sort -u > /tmp/whatis.db.$$ 96 cp /tmp/whatis.db.$$ /usr/share/man/whatis.db 97 chmod 644 /usr/share/man/whatis.db 98 rm -f /tmp/whatis.db.$$ 99fi 100 101echo "" 102echo "Rotating mail log:" 103cd /var/log 104rm -f maillog.7.Z 105if [ -f maillog.6.Z ]; then mv -f maillog.6.Z maillog.7.Z; fi 106if [ -f maillog.5.Z ]; then mv -f maillog.5.Z maillog.6.Z; fi 107if [ -f maillog.4.Z ]; then mv -f maillog.4.Z maillog.5.Z; fi 108if [ -f maillog.3.Z ]; then mv -f maillog.3.Z maillog.4.Z; fi 109if [ -f maillog.2.Z ]; then mv -f maillog.2.Z maillog.3.Z; fi 110if [ -f maillog.1.Z ]; then mv -f maillog.1.Z maillog.2.Z; fi 111if [ -f maillog.0.Z ]; then mv -f maillog.0.Z maillog.1.Z; fi 112mv -f maillog maillog.0 113compress -f maillog.0 114cp /dev/null maillog 115chmod 600 maillog 116kill -1 `cat /var/run/syslog.pid` 117 118 119cd / 120 121if [ -d /var/spool/uucp -a -f /etc/uuclean.daily ]; then 122 echo "" 123 echo "Cleaning up UUCP:" 124 echo /etc/uuclean.daily | su daemon 125fi 126 127echo "" 128echo "" 129echo "Checking subsystem status:" 130echo "" 131echo "disks:" 132df -k 133echo "" 134dump W 135echo "" 136 137 138echo "" 139echo "mail:" 140mailq 141 142if [ -d /var/spool/uucp ]; then 143 echo "" 144 echo "uucp:" 145 uustat -a 146fi 147 148echo "" 149echo "network:" 150netstat -i 151echo "" 152ruptime 153 154echo "" 155echo "Checking filesystems:" 156fsck -n | grep -v '^\*\* Phase' 157 158echo "" 159if [ -f /etc/Distfile ]; then 160 echo "Running rdist:" 161 rdist -f /etc/Distfile 162fi 163 164sh /etc/security | mail -s "daily insecurity output" root 165