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