1# 2# $OpenBSD: weekly,v 1.25 2011/07/07 23:09:46 guenther Exp $ 3# 4# For local additions, create the file /etc/weekly.local. 5# To get section headers, use the function next_part in weekly.local. 6# 7umask 022 8 9PARTOUT=/var/log/weekly.part 10MAINOUT=/var/log/weekly.out 11install -o 0 -g 0 -m 600 /dev/null $PARTOUT 12install -o 0 -g 0 -m 600 -b /dev/null $MAINOUT 13 14start_part() { 15 TITLE=$1 16 exec > $PARTOUT 2>&1 17} 18 19end_part() { 20 exec >> $MAINOUT 2>&1 21 test -s $PARTOUT || return 22 echo "" 23 echo "$TITLE" 24 cat $PARTOUT 25} 26 27next_part() { 28 end_part 29 start_part "$1" 30} 31 32run_script() { 33 f=/etc/$1 34 test -e $f || return 35 if [ `stat -f '%Sp%u' $f | cut -b1,6,9,11-` != '---0' ]; then 36 echo "$f has insecure permissions, skipping:" 37 ls -l $f 38 return 39 fi 40 . $f 41} 42 43start_part "Running weekly.local:" 44run_script "weekly.local" 45 46next_part "Rebuilding locate database:" 47if [ -f /var/db/locate.database ]; then 48 if TMP=`mktemp /var/db/locate.database.XXXXXXXXXX`; then 49 trap 'rm -f $TMP; exit 1' 0 1 15 50 UPDATEDB="/usr/libexec/locate.updatedb" 51 echo "${UPDATEDB} --fcodes=- --tmpdir=${TMPDIR:-/var/tmp}" | \ 52 nice -5 su -m nobody 2>/dev/null 1>$TMP 53 if [ -s "$TMP" ]; then 54 chmod 444 $TMP 55 chown root:wheel $TMP 56 mv -f $TMP /var/db/locate.database 57 else 58 echo "Not installing locate database; zero size" 59 fi 60 else 61 echo "Not rebuilding locate database; can't create temp file" 62 fi 63fi 64 65next_part "Rebuilding whatis databases:" 66/usr/libexec/makewhatis 67 68next_part "Doing login accounting:" 69[ "X$LOGINACCOUNTING" = X1 ] && { 70 ac -p | sort -nr -k 2 71} 72 73end_part 74rm -f $PARTOUT 75 76[ -s $MAINOUT ] && mail -s "`hostname` weekly output" root < $MAINOUT 77