181ea85a8SBrad Davis#!/bin/sh - 281ea85a8SBrad Davis# 381ea85a8SBrad Davis# 481ea85a8SBrad Davis 581ea85a8SBrad Davis# If there is a global system configuration file, suck it in. 681ea85a8SBrad Davis# 781ea85a8SBrad Davisif [ -r /etc/defaults/periodic.conf ] 881ea85a8SBrad Davisthen 981ea85a8SBrad Davis . /etc/defaults/periodic.conf 1081ea85a8SBrad Davis source_periodic_confs 1181ea85a8SBrad Davisfi 1281ea85a8SBrad Davis 1381ea85a8SBrad Davisoldmask=$(umask) 1481ea85a8SBrad Davisumask 066 1581ea85a8SBrad Daviscase "$monthly_accounting_enable" in 1681ea85a8SBrad Davis [Yy][Ee][Ss]) 1781ea85a8SBrad Davis W=/var/log/utx.log 1881ea85a8SBrad Davis rc=0 1981ea85a8SBrad Davis remove=NO 20*774bb1c2SCeri Davies filetoread=$W.0 2181ea85a8SBrad Davis if [ ! -f $W.0 ] 2281ea85a8SBrad Davis then 23*774bb1c2SCeri Davies if [ -f $W.0.gz ] || [ -f $W.0.bz2 ] || [ -f $W.0.xz ] || [ -f $W.0.zst ] 24*774bb1c2SCeri Davies then 25*774bb1c2SCeri Davies TMP=`mktemp -t accounting` 26*774bb1c2SCeri Davies remove=YES 27*774bb1c2SCeri Davies filetoread=$TMP 2881ea85a8SBrad Davis if [ -f $W.0.gz ] 2981ea85a8SBrad Davis then 30*774bb1c2SCeri Davies zcat $W.0.gz > $TMP || rc=1 3181ea85a8SBrad Davis elif [ -f $W.0.bz2 ] 3281ea85a8SBrad Davis then 33*774bb1c2SCeri Davies bzcat $W.0.bz2 > $TMP || rc=1 34*774bb1c2SCeri Davies elif [ -f $W.0.xz ] 35*774bb1c2SCeri Davies then 36*774bb1c2SCeri Davies xzcat $W.0.xz > $TMP || rc=1 37*774bb1c2SCeri Davies elif [ -f $W.0.zst ] 38*774bb1c2SCeri Davies then 39*774bb1c2SCeri Davies zstdcat $W.0.zst > $TMP || rc=1 40*774bb1c2SCeri Davies else 41*774bb1c2SCeri Davies # shouldn't get here, unless something disappeared under us. 42*774bb1c2SCeri Davies rc=2 43*774bb1c2SCeri Davies fi 4481ea85a8SBrad Davis else 4581ea85a8SBrad Davis echo '$monthly_accounting_enable is set but' \ 4681ea85a8SBrad Davis "$W.0 doesn't exist" 4781ea85a8SBrad Davis rc=2 4881ea85a8SBrad Davis fi 4981ea85a8SBrad Davis fi 5081ea85a8SBrad Davis if [ $rc -eq 0 ] 5181ea85a8SBrad Davis then 5281ea85a8SBrad Davis echo "" 5381ea85a8SBrad Davis echo "Doing login accounting:" 5481ea85a8SBrad Davis 55*774bb1c2SCeri Davies rc=$(ac -p -w $filetoread | sort -nr -k 2 | tee /dev/stderr | wc -l) 5681ea85a8SBrad Davis [ $rc -gt 0 ] && rc=1 5781ea85a8SBrad Davis fi 58*774bb1c2SCeri Davies [ $remove = YES ] && rm -f $TMP;; 5981ea85a8SBrad Davis 6081ea85a8SBrad Davis *) rc=0;; 6181ea85a8SBrad Davisesac 6281ea85a8SBrad Davis 6381ea85a8SBrad Davisumask $oldmask 6481ea85a8SBrad Davisexit $rc 65