4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / etc / daily
index 10d4dcc..a3b5a5d 100644 (file)
 #!/bin/sh -
 #
 #!/bin/sh -
 #
-#      @(#)daily       5.2 (Berkeley) %G%
+#      @(#)daily       8.1 (Berkeley) %G%
 #
 #
-
-PATH=/usr/local:/usr/ucb:/bin:/usr/bin:/etc:/sbin:/usr/sbin
-export PATH
-
-host=`hostname -s`
+PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
+host=`hostname`
 echo "Subject: $host daily run output"
 bak=/var/backups
 
 echo ""
 echo "Removing scratch and junk files:"
 if [ -d /tmp ]; then
 echo "Subject: $host daily run output"
 bak=/var/backups
 
 echo ""
 echo "Removing scratch and junk files:"
 if [ -d /tmp ]; then
-       cd /tmp
-       find .  ! -name . -atime +3 -exec rm -f {} \;
-       find .  ! -name . -type d -mtime +1 -exec rmdir {} \; >/dev/null 2>&1
+       cd /tmp && {
+       find . -type f -atime +3 -exec rm -f -- {} \;
+       find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
+           >/dev/null 2>&1; }
 fi
 
 fi
 
-#if [ -d /var/tmp ]; then
-#      cd /var/tmp
-#      find .  ! -name . -atime +7 -exec rm -f {} \;
-#      find .  ! -name . -type d -mtime +1 -exec rmdir {} \; >/dev/null 2>&1
-#fi
+if [ -d /var/tmp -a "X$CLEANVARTMP" = X1 ]; then
+       cd /var/tmp && {
+       find . ! -name . -atime +7 -exec rm -f -- {} \;
+       find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
+           >/dev/null 2>&1; }
+fi
 
 if [ -d /scratch ]; then
 
 if [ -d /scratch ]; then
-       cd /scratch
-       find .  ! -name . -atime +1 -exec rm -f {} \;
-       find .  ! -name . -type d -mtime +1 -exec rmdir {} \; >/dev/null 2>&1
+       cd /scratch && {
+       find . ! -name . -atime +1 -exec rm -f -- {} \;
+       find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
+           >/dev/null 2>&1; }
 fi
 
 if [ -d /var/preserve ]; then
 fi
 
 if [ -d /var/preserve ]; then
-       cd /var/preserve
-       find .  ! -name . -mtime +7 -exec rm -f {} \;
+       cd /var/preserve && {
+       find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
 fi
 
 fi
 
-if [ -d /var/spool/rwho ] ; then
-       cd /var/spool/rwho
-       find .  -mtime +7 -exec rm -f {} \;
+if [ -d /var/rwho ] ; then
+       cd /var/rwho && {
+       find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
 fi
 
 fi
 
-find / \( -name '[#,]*' -o -name '.#*' -o -name a.out -o -name core \
+cd /tmp
+TMP=daily.$$
+find / \( ! -fstype local -o -fstype rdonly \) -a -prune -o \
+       -name 'lost+found' -a -prune -o \
+       -name 'core.*' -a -print -o \
+       \( -name '[#,]*' -o -name '.#*' -o -name a.out \
           -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
           -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
-               -a -atime +3 -exec rm -f {} \;
+               -a -atime +3 -a -exec rm -f -- {} \; -a -print > $TMP
+echo ""
+echo "Possible core dumps:"
+egrep 'core\.' $TMP | sed '/core.[05cho]$/d'
+
+echo ""
+echo "Deleted files:"
+egrep -v 'core\.' $TMP
+
+rm -f $TMP
+       
 msgs -c
 msgs -c
-if [ -f /usr/new/lib/news/expire ]; then
-       /usr/new/lib/news/expire
+if [ -f /etc/news.expire ]; then
+       /etc/news.expire
 fi
 
 echo ""
 echo "Purging accounting records:"
 fi
 
 echo ""
 echo "Purging accounting records:"
-cp /var/account/acct /var/account/acct.yesterday
+mv /var/account/acct.2 /var/account/acct.3
+mv /var/account/acct.1 /var/account/acct.2
+mv /var/account/acct.0 /var/account/acct.1
+cp /var/account/acct /var/account/acct.0
 sa -s > /dev/null
 
 sa -s > /dev/null
 
-echo ""
-echo "Backup passwd and group files:"
-if cmp $bak/master.passwd.bak /etc/master.passwd >/dev/null; then :; else
-       echo "$host passwd diffs:"
-       diff $bak/master.passwd.bak /etc/master.passwd
-       mv $bak/master.passwd.bak $bak/master.passwd.bak2
-       cp -p /etc/master.passwd $bak/master.passwd.bak
-       chmod 600 $bak/master.passwd.bak $bak/master.passwd.bak2
-fi
-if cmp $bak/group.bak /etc/group >/dev/null; then :; else
-       mv $bak/group.bak $bak/group.bak2
-       cp -p /etc/group $bak/group.bak
-fi
-if [ -f /etc/Distfile ]; then
-       if cmp $bak/Distfile.bak /etc/Distfile >/dev/null; then :; else
-               mv $bak/Distfile.bak $bak/Distfile.bak2
-               cp /etc/Distfile $bak/Distfile.bak
-       fi
-fi
+# If ROOTBACKUP is set to 1 in the environment, and
+# if filesystem named /altroot is type ufs, on /dev/* and mounted "xx",
+# use it as a backup root filesystem to be updated daily.
+[ "X$ROOTBACKUP" = X1 ] && {
+       rootdev=`awk '$2 == "/" && $1 ~ /^\/dev\// && $3 == "ufs" && \
+           $4 == "rw" \
+                { print substr($1, 6) }' < /etc/fstab`
+       rootbak=`awk '$2 == "/altroot" && $1 ~ /^\/dev\// && $3 == "ufs" && \
+           $4 == "xx" \
+               { print substr($1, 6) }' < /etc/fstab`
+       [ X$rootdev != X -a X$rootbak != X ] && {
+               sync
+               echo ""
+               echo "Backing up root filesystem:"
+               echo "copying /dev/r$rootdev to /dev/r$rootbak"
+               dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \
+                       conv=noerror,sync
+               fsck -y /dev/r$rootbak
+       }
+}
 
 echo ""
 echo "Running calendar:"
 
 echo ""
 echo "Running calendar:"
-calendar -
-
-echo ""
-echo "Rotating mail syslog:"
-cd /var/spool/mqueue
-rm -f syslog.7
-if [ -f syslog.6 ]; then mv -f syslog.6  syslog.7; fi
-if [ -f syslog.5 ]; then mv -f syslog.5  syslog.6; fi
-if [ -f syslog.4 ]; then mv -f syslog.4  syslog.5; fi
-if [ -f syslog.3 ]; then mv -f syslog.3  syslog.4; fi
-if [ -f syslog.2 ]; then mv -f syslog.2  syslog.3; fi
-if [ -f syslog.1 ]; then mv -f syslog.1  syslog.2; fi
-if [ -f syslog.0 ]; then mv -f syslog.0  syslog.1; fi
-mv -f syslog syslog.0
-cp /dev/null syslog
-chmod 644    syslog
+calendar -a
+
+echo ""
+echo "Rotating mail log:"
+cd /var/log
+rm -f maillog.7
+if [ -f maillog.6 ]; then mv -f maillog.6  maillog.7; fi
+if [ -f maillog.5 ]; then mv -f maillog.5  maillog.6; fi
+if [ -f maillog.4 ]; then mv -f maillog.4  maillog.5; fi
+if [ -f maillog.3 ]; then mv -f maillog.3  maillog.4; fi
+if [ -f maillog.2 ]; then mv -f maillog.2  maillog.3; fi
+if [ -f maillog.1 ]; then mv -f maillog.1  maillog.2; fi
+if [ -f maillog.0 ]; then mv -f maillog.0  maillog.1; fi
+mv -f maillog maillog.0
+cp /dev/null maillog
+chmod 644    maillog
 kill -1 `cat /var/run/syslog.pid`
 cd /
 
 kill -1 `cat /var/run/syslog.pid`
 cd /
 
-if [ -d /var/spool/uucp -a -f /usr/lib/uucp/clean.daily ]; then
+if [ -d /var/spool/uucp -a -f /etc/uuclean.daily ]; then
        echo ""
        echo "Cleaning up UUCP:"
        echo ""
        echo "Cleaning up UUCP:"
-       echo /usr/lib/uucp/clean.daily | su daemon
+       echo /etc/uuclean.daily | su daemon
 fi
 
 echo ""
 fi
 
 echo ""
@@ -105,12 +124,10 @@ echo ""
 echo "Checking subsystem status:"
 echo ""
 echo "disks:"
 echo "Checking subsystem status:"
 echo ""
 echo "disks:"
-df
+env BLOCKSIZE=1k df
 echo ""
 dump W
 echo ""
 echo ""
 dump W
 echo ""
-sync
-fsck -n | grep -v '^\*\* Phase'
 
 
 echo ""
 
 
 echo ""
@@ -130,30 +147,18 @@ echo ""
 ruptime
 
 echo ""
 ruptime
 
 echo ""
-echo "SECURITY CHECKS:"
-echo ""
-echo "checking setuid files in root filesystem:"
-ncheck -s `awk -F: '$2=="/" {print $1}' /etc/fstab` | grep -v '        /dev/' \
-       > $bak/check.today
-chmod 400 $bak/check.today
-if [ -f $bak/check.yesterday ]
-then
-       if diff $bak/check.today $bak/check.yesterday > /tmp/dif; then :; else
-               echo "*** New setuid files in root filesystem:"
-               cat /tmp/dif
-               mv $bak/check.today $bak/check.yesterday
-       fi
-       rm /tmp/dif
-else
-       cat $bak/check.today
-       mv $bak/check.today $bak/check.yesterday
-fi
-echo ""
-echo "checking for uids of 0:"
-awk 'BEGIN {FS=":"} $3=="0" {print $1,$3}' /etc/master.passwd
+echo "Checking filesystems:"
+fsck -n | grep -v '^\*\* Phase'
 
 echo ""
 if [ -f /etc/Distfile ]; then
        echo "Running rdist:"
 
 echo ""
 if [ -f /etc/Distfile ]; then
        echo "Running rdist:"
-       rdist -f /etc/Distfile 
+       if [ -d /var/log/rdist ]; then
+               logf=`date | awk '{printf "%s.%s.%s", $6, $2, $3}'`
+               rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
+       else
+               rdist -f /etc/Distfile 
+       fi
 fi
 fi
+
+sh /etc/security 2>&1 | mail -s "$host daily insecurity output" root