xref: /freebsd/usr.sbin/periodic/etc/monthly/200.accounting (revision fd45b686f9d92f583366c75b22c04c7ee49709c0)
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	filetoread=$W.0
21	if [ ! -f $W.0 ]
22	then
23	    if [ -f $W.0.gz ] || [ -f $W.0.bz2 ] || [ -f $W.0.xz ] || [ -f $W.0.zst ]
24	    then
25	        TMP=`mktemp -t accounting`
26		remove=YES
27		filetoread=$TMP
28		if [ -f $W.0.gz ]
29		then
30		    zcat $W.0.gz > $TMP || rc=1
31		elif [ -f $W.0.bz2 ]
32		then
33		    bzcat $W.0.bz2 > $TMP || rc=1
34		elif [ -f $W.0.xz ]
35		then
36		    xzcat $W.0.xz > $TMP || rc=1
37		elif [ -f $W.0.zst ]
38		then
39		    zstdcat $W.0.zst > $TMP || rc=1
40		else
41		# shouldn't get here, unless something disappeared under us.
42		    rc=2
43		fi
44	    else
45		echo '$monthly_accounting_enable is set but' \
46		    "$W.0 doesn't exist"
47		rc=2
48	    fi
49	fi
50	if [ $rc -eq 0 ]
51	then
52	    echo ""
53	    echo "Doing login accounting:"
54
55	    rc=$(ac -p -w $filetoread | sort -nr -k 2 | tee /dev/stderr | wc -l)
56	    [ $rc -gt 0 ] && rc=1
57	fi
58	[ $remove = YES ] && rm -f $TMP;;
59
60    *)  rc=0;;
61esac
62
63umask $oldmask
64exit $rc
65