1#!/bin/sh 2# 3# $FreeBSD$ 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 [ $(sysctl -n kern.acct_configured) -eq 0 ] 22 then 23 echo '$daily_accounting_enable is set but' \ 24 'process accounting is not active' 25 rc=2 26 elif [ -z "$daily_accounting_save" ] 27 then 28 echo '$daily_accounting_enable is set but ' \ 29 '$daily_accounting_save is not' 30 rc=2 31 else 32 echo "" 33 echo "Rotating accounting logs and gathering statistics:" 34 35 cd /var/account 36 rc=0 37 38 n=$(( $daily_accounting_save - 1 )) 39 for f in acct.*; do 40 case "$f" in acct.\*) continue ;; esac # No files match 41 m=${f%.gz} ; m=${m#acct.} 42 [ $m -ge $n ] && { rm $f || rc=3; } 43 done 44 45 m=$n 46 n=$(($n - 1)) 47 while [ $n -ge 0 ] 48 do 49 [ -f acct.$n.gz ] && { mv -f acct.$n.gz acct.$m.gz || rc=3; } 50 [ -f acct.$n ] && { mv -f acct.$n acct.$m || rc=3; } 51 m=$n 52 n=$(($n - 1)) 53 done 54 55 /etc/rc.d/accounting onerotate_log || rc=3 56 57 rm -f acct.merge && cp acct.0 acct.merge || rc=3 58 sa -s $daily_accounting_flags /var/account/acct.merge || rc=3 59 rm acct.merge 60 61 case "$daily_accounting_compress" in 62 [Yy][Ee][Ss]) 63 gzip -f acct.0 || rc=3;; 64 esac 65 fi;; 66 67 *) rc=0;; 68esac 69 70exit $rc 71