]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - etc/periodic/monthly/200.accounting
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / etc / periodic / monthly / 200.accounting
1 #!/bin/sh -
2 #
3 # $FreeBSD$
4 #
5
6 # If there is a global system configuration file, suck it in.
7 #
8 if [ -r /etc/defaults/periodic.conf ]
9 then
10     . /etc/defaults/periodic.conf
11     source_periodic_confs
12 fi
13
14 oldmask=$(umask)
15 umask 066
16 case "$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;;
48 esac
49
50 umask $oldmask
51 exit $rc