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