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