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

Diff of /parse_maillog.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dpavlin, Mon May 13 06:44:05 2002 UTC revision 1.5 by dpavlin, Fri Jul 19 13:28:07 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -wT  #!/usr/bin/perl -w
2    
3  # this script can be run periodicly on log mail.log file to report  # this script can be run periodicly on log mail.log file to report
4  # change since last run.  # change since last run.
5  #  #
6  # Dobrica Pavlinusic <dpavlin@rot13.org>  # Dobrica Pavlinusic <dpavlin@rot13.org>
7    #
8    # Usage: parse_maillog.pl /path/to/mail.log [count_regex,count_regex,...]
9    #
10    # Results for optional count regexps will be dumped to stdout after data
11    # for number of internal mails, size of internal mails, number of
12    # external mails and size of external mails
13    #
14    # So, if you want also to count number of pop and imap accesses from your
15    # mail.log you can use:
16    #
17    #       parse_maillog.pl /var/log/mail.log popd,imapd
18    #
19    # and modify your target file accordingly
20    
21  use strict;  use strict;
22    
# Line 14  my $log="/var/log/mail.log"; Line 27  my $log="/var/log/mail.log";
27  my $domain='@pliva.hr';  my $domain='@pliva.hr';
28  my $delta="/var/tmp/";  my $delta="/var/tmp/";
29    
30  my $debug=0;  my $debug=1;
31    my $skip_delta=0;
32    
33    $log = shift @ARGV if ($ARGV[0] && -r $ARGV[0]);
34    
35  $log = $ARGV[0] if ($ARGV[0] && -r $ARGV[0]);  # take patterns to count (separated by ,)
36    my @count_patt = split(/,/,shift @ARGV) if (@ARGV);
37    my %count;
38    
39  # counters  # counters
40  my ($mail_int, $mail_ext) = (0,0,0,0);  my ($mail_int, $mail_ext) = (0,0,0,0);
41  # size  # size
42  my ($size_int, $size_ext) = (0,0,0,0);  my ($size_int, $size_ext) = (0,0,0,0);
43    
44  open(LOG,$log) || die "can't open log: $!";  open(LOG,$log) || die "can't open log '$log': $!";
45    
46  my $tmp_log=$log;  my $tmp_log=$log;
47  $tmp_log=~s/\W/_/g;  $tmp_log=~s/\W/_/g;
# Line 35  if (-e $delta) { Line 53  if (-e $delta) {
53          chomp $offset;          chomp $offset;
54          close(D);          close(D);
55          my $log_size = -s $log;          my $log_size = -s $log;
56          print "log size: $log_size\n" if ($debug);          print STDERR "log size: $log_size\n" if ($debug);
57          if ($offset <= $log_size) {          if ($offset <= $log_size) {
58                  seek(LOG,$offset,0);                  seek(LOG,$offset,0);
59                  print STDERR "skipping to position: $offset\n" if ($debug);                  print STDERR "skipping to position: $offset\n" if ($debug);
# Line 55  while(<LOG>) { Line 73  while(<LOG>) {
73                  $mail_ext++;                  $mail_ext++;
74                  $size_ext+=$1;                  $size_ext+=$1;
75          }          }
76            foreach my $patt (@count_patt) {
77                    if (m/$patt/i) {
78                            $count{$patt}++;
79                    }
80            }
81          $lines++;          $lines++;
82  }  }
83    
84  print STDERR "processed $lines lines...\n" if ($debug);  print STDERR "processed $lines lines...\n" if ($debug);
85    
86  open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";  if (! $skip_delta) {
87  print D tell(LOG);          open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";
88  close(D);          print D tell(LOG);
89            close(D);
90    } else {
91            print STDERR "new delta not written to file!\n";
92    }
93    
94  print STDERR "last position in log: ".tell(LOG)."\n" if ($debug);  print STDERR "last position in log: ".tell(LOG)."\n" if ($debug);
95    
96  print "$mail_int  print "$mail_int\n$size_int\n$mail_ext\n$size_ext\n";
97  $size_int  
98  $mail_ext  foreach my $patt (@count_patt) {
99  $size_ext          print $count{$patt} || 0,"\n";
100  ";  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.26