1#
2#	$OpenBSD: monthly,v 1.13 2011/01/19 06:18:05 david Exp $
3#
4# For local additions, create the file /etc/monthly.local.
5# To get section headers, use the function next_part in monthly.local.
6#
7umask 022
8
9PARTOUT=/var/log/monthly.part
10MAINOUT=/var/log/monthly.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 monthly.local:"
44run_script "monthly.local"
45
46end_part
47rm -f $PARTOUT
48
49[ -s $MAINOUT ] && mail -s "`hostname` monthly output" root < $MAINOUT
50