[BACK]Return to daily CVS log [TXT][DIR] Up to [local] / src / etc

Annotation of src/etc/daily, Revision 1.62

1.1       deraadt     1: #
1.62    ! schwarze    2: #      $OpenBSD: daily,v 1.61 2009/05/17 00:25:34 schwarze Exp $
1.17      millert     3: #      From: @(#)daily 8.2 (Berkeley) 1/25/94
1.1       deraadt     4: #
1.56      ajacouto    5: umask 022
1.47      nick        6:
1.58      schwarze    7: PARTOUT=/var/log/daily.part
                      8: MAINOUT=/var/log/daily.out
                      9: install -o 0 -g 0 -m 600    /dev/null $PARTOUT
                     10: install -o 0 -g 0 -m 600 -b /dev/null $MAINOUT
                     11:
                     12: start_part() {
                     13:        TITLE=$1
                     14:        exec > $PARTOUT 2>&1
                     15: }
                     16:
                     17: end_part() {
                     18:        exec >> $MAINOUT 2>&1
                     19:        test -s $PARTOUT || return
1.2       david      20:        echo ""
1.58      schwarze   21:        echo "$TITLE"
                     22:        cat $PARTOUT
                     23: }
                     24:
                     25: next_part() {
                     26:        end_part
                     27:        start_part "$1"
                     28: }
1.2       david      29:
1.58      schwarze   30: run_script() {
                     31:        f=/etc/$1
                     32:        test -e $f || return
                     33:        if [ `stat -f '%Sp%u' $f | cut -b1,6,9,11-` != '---0' ]; then
                     34:                echo "$f has insecure permissions, skipping:"
                     35:                ls -l $f
                     36:                return
                     37:        fi
                     38:        . $f
1.42      pvalchev   39: }
1.16      millert    40:
1.59      schwarze   41: start_part "Running daily.local:"
1.58      schwarze   42: run_script "daily.local"
1.14      millert    43:
1.58      schwarze   44: next_part "Removing scratch and junk files:"
1.32      aaron      45: if [ -d /tmp -a ! -L /tmp ]; then
1.17      millert    46:        cd /tmp && {
1.50      millert    47:        find -x . \
                     48:            \( -path './ssh-*' -o -path ./.X11-unix -o -path ./.ICE-unix \) \
                     49:            -prune -o -type f -atime +3 -execdir rm -f -- {} \;
1.49      millert    50:        find -x . -type d -mtime +1 ! -path ./vi.recover ! -path ./.X11-unix \
1.50      millert    51:            ! -path ./.ICE-unix ! -name . -execdir rmdir -- {} \; >/dev/null 2>&1; }
1.17      millert    52: fi
1.1       deraadt    53:
1.32      aaron      54: if [ -d /var/tmp -a ! -L /var/tmp ]; then
1.17      millert    55:        cd /var/tmp && {
1.50      millert    56:        find -x . \
                     57:            \( -path './ssh-*' -o -path ./.X11-unix -o -path ./.ICE-unix \) \
                     58:            -prune -o ! -type d -atime +7 -execdir rm -f -- {} \;
1.49      millert    59:        find -x . -type d -mtime +1 ! -path ./vi.recover ! -path ./.X11-unix \
1.50      millert    60:            ! -path ./.ICE-unix ! -name . -execdir rmdir -- {} \; >/dev/null 2>&1; }
1.17      millert    61: fi
1.1       deraadt    62:
1.3       deraadt    63: # Additional junk directory cleanup would go like this:
1.32      aaron      64: #if [ -d /scratch -a ! -L /scratch ]; then
1.3       deraadt    65: #      cd /scratch && {
1.17      millert    66: #      find . ! -name . -atime +1 -execdir rm -f -- {} \;
                     67: #      find . ! -name . -type d -mtime +1 -execdir rmdir -- {} \; \
1.3       deraadt    68: #          >/dev/null 2>&1; }
                     69: #fi
1.17      millert    70:
1.32      aaron      71: if [ -d /var/rwho -a ! -L /var/rwho ] ; then
1.17      millert    72:        cd /var/rwho && {
                     73:        find . ! -name . -mtime +7 -execdir rm -f -- {} \; ; }
1.14      millert    74: fi
1.1       deraadt    75:
1.26      downsj     76: if [ -d /var/msgs -a ! -L /var/msgs ]; then
                     77:        msgs -c
1.1       deraadt    78: fi
                     79:
1.58      schwarze   80: next_part "Purging accounting records:"
1.1       deraadt    81: if [ -f /var/account/acct ]; then
1.44      mickey     82:        mv -f /var/account/acct.2 /var/account/acct.3
                     83:        mv -f /var/account/acct.1 /var/account/acct.2
                     84:        mv -f /var/account/acct.0 /var/account/acct.1
                     85:        cp -f /var/account/acct /var/account/acct.0
1.17      millert    86:        sa -sq
                     87: fi
                     88:
                     89: # If ROOTBACKUP is set to 1 in the environment, and
                     90: # if filesystem named /altroot is type ffs, on /dev/* and mounted "xx",
                     91: # use it as a backup root filesystem to be updated daily.
1.58      schwarze   92: next_part "Backing up root filesystem:"
1.17      millert    93: [ "X$ROOTBACKUP" = X1 ] && {
1.48      millert    94:        rootdev=`df -n / | awk '/^\/dev\// { print substr($1, 6) }'`
1.17      millert    95:        rootbak=`awk '$2 == "/altroot" && $1 ~ /^\/dev\// && $3 == "ffs" && \
1.29      todd       96:            $4 ~ /xx/ \
1.17      millert    97:                { print substr($1, 6) }' < /etc/fstab`
1.48      millert    98:        [ X$rootdev != X -a X$rootbak != X -a X$rootdev != X$rootbak ] && {
1.58      schwarze   99:                next_part "Backing up root=/dev/r$rootdev to /dev/r$rootbak:"
1.17      millert   100:                sync
                    101:                dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \
1.22      mickey    102:                        conv=noerror
1.17      millert   103:                fsck -y /dev/r$rootbak
                    104:        }
                    105: }
1.1       deraadt   106:
1.61      schwarze  107: next_part "Checking subsystem status:"
1.60      schwarze  108: if [ "X$VERBOSESTATUS" != X0 ]; then
                    109:        echo ""
                    110:        echo "disks:"
                    111:        df -kl
                    112:        echo ""
                    113:        dump W
                    114: fi
1.1       deraadt   115:
1.58      schwarze  116: # The first two regular expressions handle sendmail, the third postfix.
                    117: # When the queue is empty, exim -bp keeps silent.
1.59      schwarze  118: next_part "mail:"
1.58      schwarze  119: mailq | grep -v -e "^/var/spool/mqueue is empty$" \
                    120:                -e "^[[:blank:]]*Total requests: 0$" \
                    121:                -e "^Mail queue is empty$"
1.1       deraadt   122:
1.59      schwarze  123: next_part "network:"
1.60      schwarze  124: if [ "X$VERBOSESTATUS" != X0 ]; then
                    125:        netstat -ivn
1.14      millert   126:
1.60      schwarze  127:        t=/var/rwho/*
                    128:        if [ "$t" != '/var/rwho/*' ]; then
                    129:                echo ""
                    130:                ruptime
                    131:        fi
1.38      millert   132: fi
                    133:
1.58      schwarze  134: next_part "Running calendar in the background:"
                    135: if [ "X$CALENDAR" != X0 -a \
                    136:      \( -d /var/yp/`domainname` -o ! -d /var/yp/binding \) ]; then
1.38      millert   137:        calendar -a &
1.14      millert   138: fi
1.1       deraadt   139:
1.17      millert   140: # If CHECKFILESYSTEMS is set to 1 in the environment, run fsck
                    141: # with the no-write flag.
1.58      schwarze  142: next_part "Checking filesystems:"
1.17      millert   143: [ "X$CHECKFILESYSTEMS" = X1 ] && {
                    144:        fsck -n | grep -v '^\*\* Phase'
                    145: }
1.1       deraadt   146:
1.58      schwarze  147: next_part "Running rdist:"
1.1       deraadt   148: if [ -f /etc/Distfile ]; then
1.17      millert   149:        if [ -d /var/log/rdist ]; then
1.19      deraadt   150:                logf=`date +%Y.%b.%e`
1.17      millert   151:                rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
                    152:        else
1.39      deraadt   153:                rdist -f /etc/Distfile
1.17      millert   154:        fi
1.1       deraadt   155: fi
                    156:
1.58      schwarze  157: end_part
1.61      schwarze  158: [ -s $MAINOUT ] && {
                    159:        sysctl -n kern.version
                    160:        uptime
                    161:        cat $MAINOUT
                    162: } 2>&1 | mail -s "`hostname` daily output" root
1.58      schwarze  163:
                    164:
                    165: MAINOUT=/var/log/security.out
                    166: install -o 0 -g 0 -m 600 -b /dev/null $MAINOUT
                    167:
                    168: start_part "Running /etc/security:"
                    169: run_script "security"
                    170: end_part
                    171: rm -f $PARTOUT
                    172:
                    173: [ -s $MAINOUT ] && mail -s "`hostname` daily insecurity output" root < $MAINOUT