/[cricket]/parse_maillog.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /parse_maillog.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Mon May 13 06:44:05 2002 UTC (19 years, 5 months ago) by dpavlin
Branch: MAIN
Changes since 1.2: +2 -0 lines
File MIME type: text/plain
log as a parameter to script

1 dpavlin 1.1 #!/usr/bin/perl -wT
2    
3     # this script can be run periodicly on log mail.log file to report
4     # change since last run.
5     #
6     # Dobrica Pavlinusic <dpavlin@rot13.org>
7    
8     use strict;
9    
10 dpavlin 1.2 my $log="/var/log/mail.log";
11 dpavlin 1.1
12     # edit this to your configuration!
13    
14     my $domain='@pliva.hr';
15     my $delta="/var/tmp/";
16    
17 dpavlin 1.2 my $debug=0;
18 dpavlin 1.1
19 dpavlin 1.3 $log = $ARGV[0] if ($ARGV[0] && -r $ARGV[0]);
20    
21 dpavlin 1.1 # counters
22     my ($mail_int, $mail_ext) = (0,0,0,0);
23     # size
24     my ($size_int, $size_ext) = (0,0,0,0);
25    
26 dpavlin 1.2 open(LOG,$log) || die "can't open log: $!";
27 dpavlin 1.1
28     my $tmp_log=$log;
29     $tmp_log=~s/\W/_/g;
30     $delta.=$tmp_log.".offset";
31    
32     if (-e $delta) {
33 dpavlin 1.2 open(D,$delta) || die "can't open delta file '$delta' for log '$log': $!";
34 dpavlin 1.1 my $offset=<D>;
35     chomp $offset;
36     close(D);
37     my $log_size = -s $log;
38     print "log size: $log_size\n" if ($debug);
39     if ($offset <= $log_size) {
40     seek(LOG,$offset,0);
41     print STDERR "skipping to position: $offset\n" if ($debug);
42     } else {
43     print STDERR "reset position to begin\n" if ($debug);
44     }
45     }
46    
47     my $lines=0;
48    
49     while(<LOG>) {
50     chomp;
51     if (m/from=[^\@]+\@[^\@]+$domain[>,]+\s+.*size=(\d+)/ || m/from=[^\@]+[,\s]+.*size=(\d+)/ ) {
52     $mail_int++;
53     $size_int+=$1;
54     } elsif (m/from=.*size=(\d+)/) {
55     $mail_ext++;
56     $size_ext+=$1;
57     }
58     $lines++;
59     }
60    
61     print STDERR "processed $lines lines...\n" if ($debug);
62    
63 dpavlin 1.2 open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";
64 dpavlin 1.1 print D tell(LOG);
65     close(D);
66    
67     print STDERR "last position in log: ".tell(LOG)."\n" if ($debug);
68    
69     print "$mail_int
70     $size_int
71     $mail_ext
72     $size_ext
73     ";

  ViewVC Help
Powered by ViewVC 1.1.26