File: tally.control.in

package info (click to toggle)
inn2 2.4.5-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,912 kB
  • ctags: 7,860
  • sloc: ansic: 85,104; perl: 11,427; sh: 9,863; makefile: 2,498; yacc: 1,563; python: 298; lex: 252; tcl: 7
file content (59 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /bin/sh
# fixscript will replace this line with code to load innshellvars

##  $Revision: 2677 $
##  Tally/update the newgroup/rmgroup control log.
##  Merge in a log that contains newgroup/rmgroup control messages so that
##  the "control.log" file is updated to contain the new counts of how
##  often each group has been newgroup'd or rmgroup'd.  This is run by
##  scanlogs, which prepares this from the control-message handlers if
##  control.ctl specifies logging.

CONTROL=${MOST_LOGS}/control.log
CONTROL_NEW=${CONTROL}.new
CONTROL_OLD=${CONTROL}.old

PROGNAME=`basename $0`
LOCK=${LOCKS}/LOCK.${PROGNAME}

##  Lock.
trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15
shlock -f ${LOCK} -p $$ || {
    echo "$0: cannot lock ${LOCK}" 1>&2
    exit 1
}

##  Prepare the files.
if [ ! -f ${CONTROL} ]; then
    touch ${CONTROL}
    chmod 0660 ${CONTROL}
fi
rm -f ${CONTROL_NEW} ${CONTROL_OLD}
ln ${CONTROL} ${CONTROL_OLD}
touch ${CONTROL_NEW}
chmod 0660 ${CONTROL_NEW}

##  Grab the data.
${SED} -n -e 's/[	 ][	 ]*/ /g' -e 's/^ \(Control:.*\)$/1 \1/p' \
    | cat - ${CONTROL} \
    | ${SED} -e 's/ /#/g' -e 's/\([0-9][0-9]*\)#\(.*\)/\1 \2/' \
    | ${AWK} 'BEGIN {
	    ctl[0]=0;
	}
	{
	    ctl[$2] += $1;
	}
	END {
	    for (line in ctl) {
		if (line != 0) {
		    print ctl[line], line;
		}
	    }
	}' \
    | tr '#' ' ' \
    | sort -n -r >${CONTROL_NEW}
mv -f ${CONTROL_NEW} ${CONTROL}

##  All done.
rm -f ${LOCK}
exit 0