1#!/bin/sh -
2#
3
4# If there is a global system configuration file, suck it in.
5#
6if [ -r /etc/defaults/periodic.conf ]
7then
8    . /etc/defaults/periodic.conf
9    source_periodic_confs
10fi
11
12oldmask=$(umask)
13umask 066
14case "$monthly_accounting_enable" in
15    [Yy][Ee][Ss])
16	W=/var/log/wtmpx
17	rc=0
18	remove=NO
19	filetoread=$W.0
20	if [ ! -f $W.0 ]
21	then
22	    if [ -f $W.0.gz ] || [ -f $W.0.bz2 ] || [ -f $W.0.xz ] || [ -f $W.0.zst ]
23	    then
24	        TMP=`mktemp -t accounting`
25		remove=YES
26		filetoread=$TMP
27		if [ -f $W.0.gz ]
28		then
29		    zcat $W.0.gz > $TMP || rc=1
30		elif [ -f $W.0.bz2 ]
31		then
32		    bzcat $W.0.bz2 > $TMP || rc=1
33		elif [ -f $W.0.xz ]
34		then
35		    xzcat $W.0.xz > $TMP || rc=1
36		elif [ -f $W.0.zst ]
37		then
38		    zstdcat $W.0.zst > $TMP || rc=1
39		else
40		# shouldn't get here, unless something disappeared under us.
41		    rc=2
42		fi
43	    else
44		echo '$monthly_accounting_enable is set but' \
45		    "$W.0 doesn't exist"
46		rc=2
47	    fi
48	fi
49	if [ $rc -eq 0 ]
50	then
51	    echo ""
52	    echo "Doing login accounting:"
53
54	    rc=$(ac -p -w $filetoread | sort -nr -k 2 | tee -a /dev/stderr | wc -l)
55	    [ $rc -gt 0 ] && rc=1
56	fi
57	[ $remove = YES ] && rm -f $TMP;;
58
59    *)  rc=0;;
60esac
61
62umask $oldmask
63exit $rc
64