daily revision 1.57
1# 2# $OpenBSD: daily,v 1.57 2009/05/03 17:16:12 schwarze Exp $ 3# From: @(#)daily 8.2 (Berkeley) 1/25/94 4# 5umask 022 6 7PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin 8 9sysctl -n kern.version 10uptime 11 12if [ -f /etc/daily.local ]; then 13 echo "" 14 echo "Running daily.local:" 15 . /etc/daily.local 16fi 17 18TMP=`mktemp /tmp/_daily.XXXXXXXXXX` || exit 1 19OUT=`mktemp /tmp/_security.XXXXXXXXXX` || { 20 rm -f ${TMP} 21 exit 1 22} 23 24trap 'rm -f $TMP $OUT; exit 1' 0 1 15 25 26echo "" 27echo "Removing scratch and junk files:" 28if [ -d /tmp -a ! -L /tmp ]; then 29 cd /tmp && { 30 find -x . \ 31 \( -path './ssh-*' -o -path ./.X11-unix -o -path ./.ICE-unix \) \ 32 -prune -o -type f -atime +3 -execdir rm -f -- {} \; 33 find -x . -type d -mtime +1 ! -path ./vi.recover ! -path ./.X11-unix \ 34 ! -path ./.ICE-unix ! -name . -execdir rmdir -- {} \; >/dev/null 2>&1; } 35fi 36 37if [ -d /var/tmp -a ! -L /var/tmp ]; then 38 cd /var/tmp && { 39 find -x . \ 40 \( -path './ssh-*' -o -path ./.X11-unix -o -path ./.ICE-unix \) \ 41 -prune -o ! -type d -atime +7 -execdir rm -f -- {} \; 42 find -x . -type d -mtime +1 ! -path ./vi.recover ! -path ./.X11-unix \ 43 ! -path ./.ICE-unix ! -name . -execdir rmdir -- {} \; >/dev/null 2>&1; } 44fi 45 46# Additional junk directory cleanup would go like this: 47#if [ -d /scratch -a ! -L /scratch ]; then 48# cd /scratch && { 49# find . ! -name . -atime +1 -execdir rm -f -- {} \; 50# find . ! -name . -type d -mtime +1 -execdir rmdir -- {} \; \ 51# >/dev/null 2>&1; } 52#fi 53 54if [ -d /var/rwho -a ! -L /var/rwho ] ; then 55 cd /var/rwho && { 56 find . ! -name . -mtime +7 -execdir rm -f -- {} \; ; } 57fi 58 59if [ -d /var/msgs -a ! -L /var/msgs ]; then 60 msgs -c 61fi 62 63if [ -f /var/account/acct ]; then 64 echo "" 65 echo "Purging accounting records:" 66 mv -f /var/account/acct.2 /var/account/acct.3 67 mv -f /var/account/acct.1 /var/account/acct.2 68 mv -f /var/account/acct.0 /var/account/acct.1 69 cp -f /var/account/acct /var/account/acct.0 70 sa -sq 71fi 72 73# If ROOTBACKUP is set to 1 in the environment, and 74# if filesystem named /altroot is type ffs, on /dev/* and mounted "xx", 75# use it as a backup root filesystem to be updated daily. 76[ "X$ROOTBACKUP" = X1 ] && { 77 rootdev=`df -n / | awk '/^\/dev\// { print substr($1, 6) }'` 78 rootbak=`awk '$2 == "/altroot" && $1 ~ /^\/dev\// && $3 == "ffs" && \ 79 $4 ~ /xx/ \ 80 { print substr($1, 6) }' < /etc/fstab` 81 [ X$rootdev != X -a X$rootbak != X -a X$rootdev != X$rootbak ] && { 82 sync 83 echo "" 84 echo "Backing up root filesystem:" 85 echo "copying /dev/r$rootdev to /dev/r$rootbak" 86 dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \ 87 conv=noerror 88 fsck -y /dev/r$rootbak 89 } 90} 91 92# Rotation of mail log now handled automatically by cron and 'newsyslog' 93 94echo "" 95echo "Checking subsystem status:" 96echo "" 97echo "disks:" 98df -kl 99echo "" 100dump W 101echo "" 102 103mailq > $TMP 104if ! grep -q "^/var/spool/mqueue is empty$" $TMP; then 105 echo "" 106 echo "mail:" 107 cat $TMP 108fi 109 110echo "" 111echo "network:" 112netstat -ivn 113echo "" 114 115t=/var/rwho/* 116if [ "$t" != '/var/rwho/*' ]; then 117 echo "" 118 ruptime 119fi 120 121echo "" 122if [ -d /var/yp/binding -a ! -d /var/yp/`domainname` -o "X$CALENDAR" = X0 ] 123then 124 if [ "X$CALENDAR" = X0 ]; then 125 echo "Not running calendar, (disabled)." 126 else 127 echo "Not running calendar, (yp client)." 128 fi 129else 130 echo "Running calendar in the background." 131 calendar -a & 132fi 133 134# If CHECKFILESYSTEMS is set to 1 in the environment, run fsck 135# with the no-write flag. 136[ "X$CHECKFILESYSTEMS" = X1 ] && { 137 echo "" 138 echo "Checking filesystems:" 139 fsck -n | grep -v '^\*\* Phase' 140} 141 142if [ -f /etc/Distfile ]; then 143 echo "" 144 echo "Running rdist:" 145 if [ -d /var/log/rdist ]; then 146 logf=`date +%Y.%b.%e` 147 rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf 148 else 149 rdist -f /etc/Distfile 150 fi 151fi 152 153sh /etc/security 2>&1 > $OUT 154if [ -s $OUT ]; then 155 mail -s "`hostname` daily insecurity output" root < $OUT 156fi 157