Annotation of src/etc/daily, Revision 1.63
1.1 deraadt 1: #
1.63 ! schwarze 2: # $OpenBSD: daily,v 1.62 2009/05/18 20:07:35 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.63 ! schwarze 98: [ X$rootdev != X -a X$rootbak != X -a X$rootdev != X$rootbak ] && \
! 99: sysctl -n hw.disknames | grep -Fqw ${rootbak%[a-p]} && {
1.58 schwarze 100: next_part "Backing up root=/dev/r$rootdev to /dev/r$rootbak:"
1.17 millert 101: sync
102: dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \
1.22 mickey 103: conv=noerror
1.17 millert 104: fsck -y /dev/r$rootbak
105: }
106: }
1.1 deraadt 107:
1.61 schwarze 108: next_part "Checking subsystem status:"
1.60 schwarze 109: if [ "X$VERBOSESTATUS" != X0 ]; then
110: echo ""
111: echo "disks:"
112: df -kl
113: echo ""
114: dump W
115: fi
1.1 deraadt 116:
1.58 schwarze 117: # The first two regular expressions handle sendmail, the third postfix.
118: # When the queue is empty, exim -bp keeps silent.
1.59 schwarze 119: next_part "mail:"
1.58 schwarze 120: mailq | grep -v -e "^/var/spool/mqueue is empty$" \
121: -e "^[[:blank:]]*Total requests: 0$" \
122: -e "^Mail queue is empty$"
1.1 deraadt 123:
1.59 schwarze 124: next_part "network:"
1.60 schwarze 125: if [ "X$VERBOSESTATUS" != X0 ]; then
126: netstat -ivn
1.14 millert 127:
1.60 schwarze 128: t=/var/rwho/*
129: if [ "$t" != '/var/rwho/*' ]; then
130: echo ""
131: ruptime
132: fi
1.38 millert 133: fi
134:
1.58 schwarze 135: next_part "Running calendar in the background:"
136: if [ "X$CALENDAR" != X0 -a \
137: \( -d /var/yp/`domainname` -o ! -d /var/yp/binding \) ]; then
1.38 millert 138: calendar -a &
1.14 millert 139: fi
1.1 deraadt 140:
1.17 millert 141: # If CHECKFILESYSTEMS is set to 1 in the environment, run fsck
142: # with the no-write flag.
1.58 schwarze 143: next_part "Checking filesystems:"
1.17 millert 144: [ "X$CHECKFILESYSTEMS" = X1 ] && {
145: fsck -n | grep -v '^\*\* Phase'
146: }
1.1 deraadt 147:
1.58 schwarze 148: next_part "Running rdist:"
1.1 deraadt 149: if [ -f /etc/Distfile ]; then
1.17 millert 150: if [ -d /var/log/rdist ]; then
1.19 deraadt 151: logf=`date +%Y.%b.%e`
1.17 millert 152: rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
153: else
1.39 deraadt 154: rdist -f /etc/Distfile
1.17 millert 155: fi
1.1 deraadt 156: fi
157:
1.58 schwarze 158: end_part
1.61 schwarze 159: [ -s $MAINOUT ] && {
160: sysctl -n kern.version
161: uptime
162: cat $MAINOUT
163: } 2>&1 | mail -s "`hostname` daily output" root
1.58 schwarze 164:
165:
166: MAINOUT=/var/log/security.out
167: install -o 0 -g 0 -m 600 -b /dev/null $MAINOUT
168:
169: start_part "Running /etc/security:"
170: run_script "security"
171: end_part
172: rm -f $PARTOUT
173:
174: [ -s $MAINOUT ] && mail -s "`hostname` daily insecurity output" root < $MAINOUT