#!/bin/sh
infile=$1
tmpfile=$1.tmp
outfile=$1.csv
rm $tmpfile $outfile
## Nov 22 08:13:06 skapet spop3d[55948]: authentication failed for user root - ns1.sgtechzone.com (23.250.123.129)
grep "authentication failed for" $infile  | awk '{print $13","$12","$10}' | tr -d '()' | sort | uniq -c | awk '{ print $2",,,,,,"$1 }' >>$tmpfile
## Nov 23 01:43:31 skapet spop3d[27186]: authentication failed: no such user: mail - ns1.sgtechzone.com (23.250.123.129)
grep -v "authentication failed for" $infile | awk '{print $14","$13","$11}' | tr -d '()' | sort | uniq -c | awk '{ print $2",,,,,,"$1 }' >>$tmpfile
echo "IP Address","Hostname","Username","In spamtraps","Network","Netname","Country","Name","Attempts" >$outfile
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n < $tmpfile >>$outfile
