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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.26