xref: /freebsd-13-stable/usr.sbin/periodic/etc/monthly/200.accounting (revision 023fc80ee38a117fa65b2ccb2abf8bdc7dbd6fd9)
1#!/bin/sh -
2#
3#
4
5# If there is a global system configuration file, suck it in.
6#
7if [ -r /etc/defaults/periodic.conf ]
8then
9    . /etc/defaults/periodic.conf
10    source_periodic_confs
11fi
12
13oldmask=$(umask)
14umask 066
15case "$monthly_accounting_enable" in
16    [Yy][Ee][Ss])
17	W=/var/log/utx.log
18	rc=0
19	remove=NO
20	if [ ! -f $W.0 ]
21	then
22	    if [ -f $W.0.gz ]
23	    then
24		remove=YES
25		zcat $W.0.gz > $W.0 || rc=1
26	    elif [ -f $W.0.bz2 ]
27	    then
28		remove=YES
29		bzcat $W.0.bz2 > $W.0 || rc=1
30	    else
31		echo '$monthly_accounting_enable is set but' \
32		    "$W.0 doesn't exist"
33		rc=2
34	    fi
35	fi
36	if [ $rc -eq 0 ]
37	then
38	    echo ""
39	    echo "Doing login accounting:"
40
41	    rc=$(ac -p -w $W.0 | sort -nr -k 2 | tee /dev/stderr | wc -l)
42	    [ $rc -gt 0 ] && rc=1
43	fi
44	[ $remove = YES ] && rm -f $W.0;;
45
46    *)  rc=0;;
47esac
48
49umask $oldmask
50exit $rc
51