/[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

Contents of /parse_maillog.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon May 13 06:40:10 2002 UTC (21 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +5 -5 lines
File MIME type: text/plain
better error reporing

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 my $log="/var/log/mail.log";
11
12 # edit this to your configuration!
13
14 my $domain='@pliva.hr';
15 my $delta="/var/tmp/";
16
17 my $debug=0;
18
19 # counters
20 my ($mail_int, $mail_ext) = (0,0,0,0);
21 # size
22 my ($size_int, $size_ext) = (0,0,0,0);
23
24 open(LOG,$log) || die "can't open log: $!";
25
26 my $tmp_log=$log;
27 $tmp_log=~s/\W/_/g;
28 $delta.=$tmp_log.".offset";
29
30 if (-e $delta) {
31 open(D,$delta) || die "can't open delta file '$delta' for log '$log': $!";
32 my $offset=<D>;
33 chomp $offset;
34 close(D);
35 my $log_size = -s $log;
36 print "log size: $log_size\n" if ($debug);
37 if ($offset <= $log_size) {
38 seek(LOG,$offset,0);
39 print STDERR "skipping to position: $offset\n" if ($debug);
40 } else {
41 print STDERR "reset position to begin\n" if ($debug);
42 }
43 }
44
45 my $lines=0;
46
47 while(<LOG>) {
48 chomp;
49 if (m/from=[^\@]+\@[^\@]+$domain[>,]+\s+.*size=(\d+)/ || m/from=[^\@]+[,\s]+.*size=(\d+)/ ) {
50 $mail_int++;
51 $size_int+=$1;
52 } elsif (m/from=.*size=(\d+)/) {
53 $mail_ext++;
54 $size_ext+=$1;
55 }
56 $lines++;
57 }
58
59 print STDERR "processed $lines lines...\n" if ($debug);
60
61 open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";
62 print D tell(LOG);
63 close(D);
64
65 print STDERR "last position in log: ".tell(LOG)."\n" if ($debug);
66
67 print "$mail_int
68 $size_int
69 $mail_ext
70 $size_ext
71 ";

  ViewVC Help
Powered by ViewVC 1.1.26