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