Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Created March 27, 2016 18:12
Show Gist options
  • Select an option

  • Save jniltinho/270fd344fa7d62f5a948 to your computer and use it in GitHub Desktop.

Select an option

Save jniltinho/270fd344fa7d62f5a948 to your computer and use it in GitHub Desktop.
Get sasl AUTH Postfix
#!/usr/bin/perl
$ENV{"LANG"}="C";
use strict;
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin";
my %hash_mail = ();
my $total;
my $LOG_FILE = '/var/log/mail.log';
my $MES = `date | awk '{ print \$2}'`;
my $DIA = `date | awk '{ print \$3}'`;
chomp($MES);
chomp($DIA);
my $CMD = qq{cat $LOG_FILE | grep client= |grep sasl_method=};
my @lines=qx|$CMD| or die("Can't get info from cat: ".$!);
foreach(@lines){
chomp;
#print "$_\n";
if (m/$MES $DIA \S+ \S+ \S+ \S+ client\=\S+\[(\d+\.\d+\.\d+\.\d+)\]\, \S+ sasl_username=(\S+)$/i) {
print "IP=$1 E-MAIL=$2 \n";
$hash_mail{$2}++;
}
if (m/$MES $DIA \S+ \S+ \S+ \S+ client\=\S+\[(\d+\.\d+\.\d+\.\d+)\]\, \S+ sasl_username=(\S+)$/i) {
print "IP=$1 E-MAIL=$2 \n";
$hash_mail{$2}++;
}
}
print"\nTOTAL\tDE CONEXAO SMTP EFETUADA PELO CLIENTE\n";
print"-----
----------------------------------------------------------------\n";
foreach my $key (reverse sort { $hash_mail{$a} <=> $hash_mail{$b}} keys %hash_mail) {
$total += $hash_mail{$key};
if ($hash_mail{$key} > 20){ print "$hash_mail{$key} - $key\n";}
}
print"\n$total -> TOTAL DE LOGIN\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment