chiark / gitweb /
better stats for missing
[inn-innduct.git] / scripts / tally.control.in
1 #! /bin/sh
2 # fixscript will replace this line with code to load innshellvars
3
4 ##  $Revision: 2677 $
5 ##  Tally/update the newgroup/rmgroup control log.
6 ##  Merge in a log that contains newgroup/rmgroup control messages so that
7 ##  the "control.log" file is updated to contain the new counts of how
8 ##  often each group has been newgroup'd or rmgroup'd.  This is run by
9 ##  scanlogs, which prepares this from the control-message handlers if
10 ##  control.ctl specifies logging.
11
12 CONTROL=${MOST_LOGS}/control.log
13 CONTROL_NEW=${CONTROL}.new
14 CONTROL_OLD=${CONTROL}.old
15
16 PROGNAME=`basename $0`
17 LOCK=${LOCKS}/LOCK.${PROGNAME}
18
19 ##  Lock.
20 trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15
21 shlock -f ${LOCK} -p $$ || {
22     echo "$0: cannot lock ${LOCK}" 1>&2
23     exit 1
24 }
25
26 ##  Prepare the files.
27 if [ ! -f ${CONTROL} ]; then
28     touch ${CONTROL}
29     chmod 0660 ${CONTROL}
30 fi
31 rm -f ${CONTROL_NEW} ${CONTROL_OLD}
32 ln ${CONTROL} ${CONTROL_OLD}
33 touch ${CONTROL_NEW}
34 chmod 0660 ${CONTROL_NEW}
35
36 ##  Grab the data.
37 ${SED} -n -e 's/[        ][      ]*/ /g' -e 's/^ \(Control:.*\)$/1 \1/p' \
38     | cat - ${CONTROL} \
39     | ${SED} -e 's/ /#/g' -e 's/\([0-9][0-9]*\)#\(.*\)/\1 \2/' \
40     | ${AWK} 'BEGIN {
41             ctl[0]=0;
42         }
43         {
44             ctl[$2] += $1;
45         }
46         END {
47             for (line in ctl) {
48                 if (line != 0) {
49                     print ctl[line], line;
50                 }
51             }
52         }' \
53     | tr '#' ' ' \
54     | sort -n -r >${CONTROL_NEW}
55 mv -f ${CONTROL_NEW} ${CONTROL}
56
57 ##  All done.
58 rm -f ${LOCK}
59 exit 0