128263Spst#!/bin/sh 228263Spst# 350472Speter# $FreeBSD: releng/10.2/etc/periodic/daily/310.accounting 227482 2011-11-13 03:01:58Z dougb $ 428263Spst# 528263Spst 661981Sbrian# If there is a global system configuration file, suck it in. 761981Sbrian# 861981Sbrianif [ -r /etc/defaults/periodic.conf ] 961981Sbrianthen 1061981Sbrian . /etc/defaults/periodic.conf 1161981Sbrian source_periodic_confs 1261981Sbrianfi 1328320Spst 1461981Sbriancase "$daily_accounting_enable" in 1561981Sbrian [Yy][Ee][Ss]) 1665843Sbrian if [ ! -f /var/account/acct ] 1761981Sbrian then 1865843Sbrian echo '$daily_accounting_enable is set but /var/account/acct' \ 1965843Sbrian "doesn't exist" 2065843Sbrian rc=2 2177496Sbrian elif [ -z "$daily_accounting_save" ] 2277496Sbrian then 2377496Sbrian echo '$daily_accounting_enable is set but ' \ 2477496Sbrian '$daily_accounting_save is not' 2577496Sbrian rc=2 2665843Sbrian else 2761981Sbrian echo "" 2861981Sbrian echo "Rotating accounting logs and gathering statistics:" 2961981Sbrian 3061981Sbrian cd /var/account 3165843Sbrian rc=0 32208060Sdougb 33227482Sdougb n=$(( $daily_accounting_save - 1 )) 34227482Sdougb for f in acct.*; do 35227482Sdougb case "$f" in acct.\*) continue ;; esac # No files match 36227482Sdougb m=${f%.gz} ; m=${m#acct.} 37227482Sdougb [ $m -ge $n ] && { rm $f || rc=3; } 38227482Sdougb done 39227482Sdougb 4077492Sbrian m=$n 4177492Sbrian n=$(($n - 1)) 4277492Sbrian while [ $n -ge 0 ] 4377492Sbrian do 4477492Sbrian [ -f acct.$n.gz ] && { mv -f acct.$n.gz acct.$m.gz || rc=3; } 4577492Sbrian [ -f acct.$n ] && { mv -f acct.$n acct.$m || rc=3; } 4677492Sbrian m=$n 4777492Sbrian n=$(($n - 1)) 4877492Sbrian done 4962054Sbrian 50218961Sdougb /etc/rc.d/accounting rotate_log || rc=3 51218961Sdougb 52227482Sdougb rm -f acct.merge && cp acct.0 acct.merge || rc=3 53227482Sdougb sa -s $daily_accounting_flags /var/account/acct.merge || rc=3 54227482Sdougb rm acct.merge 55227482Sdougb 5662054Sbrian case "$daily_accounting_compress" in 5762054Sbrian [Yy][Ee][Ss]) 58227482Sdougb gzip -f acct.0 || rc=3;; 5962054Sbrian esac 6061981Sbrian fi;; 6165843Sbrian 6265843Sbrian *) rc=0;; 6361981Sbrianesac 6465843Sbrian 6565843Sbrianexit $rc 66