1#!/usr/local/bin/perl 2# File: mf-analyze 3# Version: 1.11 4# Purpose: Analyzes rejected messages saved by rays-filter 5# (Run once every 24 hours) 6# Requires: mail-filter.conf, string-list.conf 7# Written by: R. Butler <butlerra@sbu.ac.uk> 8# Date: 23-Jun-2000 9# Revised: 31-Jul-2000 10# 11# Copyright (C) 2000 South Bank University, London. 12# (Please see the full copyright notice in 'copyright.txt') 13 14# Note: Assumes that the previous day's rejected messages have been 15# moved to the directory specified by '$message_files'. This 16# is done by the 'archive-rejects' script. 17 18$conf_file = "/usr/local/etc/mail-filter/mail-filter.conf"; 19$string_list = "/usr/local/etc/mail-filter/string-list.conf"; 20$work_dir = &get_work_dir($conf_file); 21$message_files = $work_dir . "/rejects/Arc-yesterday/*"; 22$out_file = $work_dir . "/analysis/analysis." . `date +"%d-%b-%Y"`; 23$count = 0; 24$total = 0; 25$args = @ARGV; 26 27open(OUT_FILE, ">$out_file") 28 || die "$0: Cannot open file $out_file for output\n"; 29print OUT_FILE "\n\n\n"; 30print OUT_FILE `date +"%d-%b-%Y %T"`; 31print OUT_FILE "Analysis of yesterday\'s rejected messages on "; 32print OUT_FILE `hostname`; 33print OUT_FILE 34 "\nNOTE: Patterns such as name=\\\".*\\.vbs\\\", representing attached\n"; 35print OUT_FILE 36 " files, will usually occur twice for each attachment.\n\n"; 37print OUT_FILE "Pattern Count\n\n"; 38&scan_message_files($string_list); 39print OUT_FILE "-------------------------------\n"; 40printf OUT_FILE "%-25s %5d\n", "TOTAL", $total; 41print OUT_FILE "===============================\n\n"; 42close(OUT_FILE); 43 44 45sub scan_message_files { 46 local($string_list) = @_; 47 open(STRING_LIST, "$string_list"); 48 while (<STRING_LIST>) { 49 if ((/#.*/ == 0) && (/^\W$/ == 0)) { 50 while (/\s$/) { 51 chop; 52 } 53 while (/^\s/) { 54 s/^\s//; 55 } 56 $pattern = $_; 57 s/\./\\\./g; 58 s/\"/\\\"/g; 59 s/\*/\\\*/g; 60 s/\^/\\\^/g; 61 s/\$/\\\$/g; 62 $command = "grep -i \'^:_ $_\' $message_files | wc -l"; 63 # print "$command\n"; 64 $count = `$command`; 65 $total += $count; 66 printf OUT_FILE "%-25s %5d\n", $pattern, $count; 67 } 68 } 69 close(STRING_LIST); 70} 71 72 73sub get_work_dir { 74 local($conf_file) = @_; 75 open(CONF_FILE, "$conf_file"); 76 while (<CONF_FILE>) { 77 if (/^\s*WORK_DIR\s*=\s*\"{0,1}([^\s\"]+)/) { 78 $work_dir = $1; 79 last; 80 } 81 } 82 close(CONF_FILE); 83 $work_dir; 84} 85 86