1#!/bin/sh
2#
3#
4
5# If there is a global system configuration file, suck it in.
6#
7if [ -r /etc/defaults/periodic.conf ]
8then
9    . /etc/defaults/periodic.conf
10    source_periodic_confs
11fi
12
13case "$daily_accounting_enable" in
14    [Yy][Ee][Ss])
15	if [ ! -f /var/account/acct ]
16	then
17	    echo '$daily_accounting_enable is set but /var/account/acct' \
18		"doesn't exist"
19	    rc=2
20	elif [ $(sysctl -n kern.acct_configured) -eq 0 ]
21	then
22	    echo '$daily_accounting_enable is set but' \
23	    'process accounting is not active'
24	    rc=2
25	elif [ -z "$daily_accounting_save" ]
26	then
27	    echo '$daily_accounting_enable is set but ' \
28		'$daily_accounting_save is not'
29	    rc=2
30	else
31	    echo ""
32	    echo "Rotating accounting logs and gathering statistics:"
33
34	    cd /var/account
35	    rc=0
36
37	    n=$(( $daily_accounting_save - 1 ))
38	    for f in acct.*; do
39	    	case "$f" in acct.\*) continue ;; esac	# No files match
40	    	m=${f%.gz} ; m=${m#acct.}
41		[ $m -ge $n ] && { rm $f || rc=3; }
42	    done
43
44	    m=$n
45	    n=$(($n - 1))
46	    while [ $n -ge 0 ]
47	    do
48		[ -f acct.$n.gz ] && { mv -f acct.$n.gz acct.$m.gz || rc=3; }
49		[ -f acct.$n ] &&    { mv -f acct.$n acct.$m || rc=3; }
50		m=$n
51		n=$(($n - 1))
52	    done
53
54	    /etc/rc.d/accounting onerotate_log || rc=3
55
56	    rm -f acct.merge && cp acct.0 acct.merge || rc=3
57	    sa -s $daily_accounting_flags /var/account/acct.merge || rc=3
58	    rm acct.merge
59
60	    case "$daily_accounting_compress" in
61		[Yy][Ee][Ss])
62		    gzip -f acct.0 || rc=3;;
63	    esac
64	fi;;
65
66    *)  rc=0;;
67esac
68
69exit $rc
70