xref: /dragonfly/etc/periodic/daily/310.accounting (revision 36a3d1d6)
1#!/bin/sh
2#
3# $FreeBSD: src/etc/periodic/daily/310.accounting,v 1.3.2.3 2001/06/13 19:36:50 brian Exp $
4# $DragonFly: src/etc/periodic/daily/310.accounting,v 1.2 2003/06/17 04:24:48 dillon Exp $
5#
6
7# If there is a global system configuration file, suck it in.
8#
9if [ -r /etc/defaults/periodic.conf ]
10then
11    . /etc/defaults/periodic.conf
12    source_periodic_confs
13fi
14
15case "$daily_accounting_enable" in
16    [Yy][Ee][Ss])
17	if [ ! -f /var/account/acct ]
18	then
19	    echo '$daily_accounting_enable is set but /var/account/acct' \
20		"doesn't exist"
21	    rc=2
22	elif [ -z "$daily_accounting_save" ]
23	then
24	    echo '$daily_accounting_enable is set but ' \
25		'$daily_accounting_save is not'
26	    rc=2
27	else
28	    echo ""
29	    echo "Rotating accounting logs and gathering statistics:"
30
31	    cd /var/account
32	    rc=0
33
34	    n=$daily_accounting_save
35	    rm -f acct.$n.gz acct.$n || rc=3
36	    m=$n
37	    n=$(($n - 1))
38	    while [ $n -ge 0 ]
39	    do
40		[ -f acct.$n.gz ] && { mv -f acct.$n.gz acct.$m.gz || rc=3; }
41		[ -f acct.$n ] &&    { mv -f acct.$n acct.$m || rc=3; }
42		m=$n
43		n=$(($n - 1))
44	    done
45	    cp -pf acct acct.0 || rc=3
46	    sa -s $daily_accounting_flags || rc=3
47
48	    case "$daily_accounting_compress" in
49		[Yy][Ee][Ss])
50		    gzip -f acct.0 || rc=3;;
51	    esac
52	fi;;
53
54    *)  rc=0;;
55esac
56
57exit $rc
58