| 1 |
#!/bin/sh |
| 2 |
## $Revision: 1.8 $ |
| 3 |
## Tally/update the unwanted newsgroup log |
| 4 |
## Read an innd log on stdin, scan it for articles that were unwanted |
| 5 |
## because they newsgroups were not in our active file. Update unwanted.log |
| 6 |
## to have the new count of unwanted groups, and how often they were used. |
| 7 |
|
| 8 |
## =()<. @<_PATH_SHELLVARS>@>()= |
| 9 |
. /var/news/etc/innshellvars |
| 10 |
|
| 11 |
PROGNAME=unwanted |
| 12 |
LOCK=${LOCKS}/LOCK.${PROGNAME} |
| 13 |
LOG=${MOST_LOGS}/unwanted.log |
| 14 |
|
| 15 |
UNWANTED_NEW=${LOG}.new |
| 16 |
UNWANTED_OLD=${LOG}.old |
| 17 |
|
| 18 |
## Lock. |
| 19 |
shlock -f ${LOCK} -p $$ || { |
| 20 |
echo "$0: cannot lock $LOCK" 1>&2 |
| 21 |
exit 2 |
| 22 |
} |
| 23 |
|
| 24 |
## Prepare the files. |
| 25 |
if [ ! -f ${LOG} ]; then |
| 26 |
touch ${LOG} |
| 27 |
chmod 0660 ${LOG} |
| 28 |
fi |
| 29 |
rm -f ${UNWANTED_NEW} ${UNWANTED_OLD} |
| 30 |
ln ${LOG} ${UNWANTED_OLD} |
| 31 |
touch ${UNWANTED_NEW} |
| 32 |
chmod 0660 ${UNWANTED_NEW} |
| 33 |
|
| 34 |
## Grab the data. |
| 35 |
${AWK} '$4 == "-" && $7 == "437" && $8 == "Unwanted" && $9 == "newsgroup" \ |
| 36 |
{ print }' \ |
| 37 |
| ${SED} 's/.* \([a-z]*\) "\(.*\)".*/\1 \2/' \ |
| 38 |
| sort \ |
| 39 |
| uniq -c \ |
| 40 |
| cat - ${LOG} \ |
| 41 |
| ${AWK} 'BEGIN { |
| 42 |
unwanted[0]=0; |
| 43 |
} |
| 44 |
{ |
| 45 |
unwanted[$2 " " $3] += $1; |
| 46 |
} |
| 47 |
END { |
| 48 |
for (group in unwanted) { |
| 49 |
if (group != 0) { |
| 50 |
print unwanted[group], group; |
| 51 |
} |
| 52 |
} |
| 53 |
}' \ |
| 54 |
| sort -n -r >${UNWANTED_NEW} |
| 55 |
mv -f ${UNWANTED_NEW} ${LOG} |
| 56 |
|
| 57 |
## All done. |
| 58 |
rm -f ${LOCK} |
| 59 |
exit 0 |