#!/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 $10","$12","$13}' | 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 $11","$13","$14}' | tr -d '()' | sort | uniq -c | awk '{ print $2",,,,,,"$1 }' >>$tmpfile
echo "User name","Hostname","IP Address","In spamtraps","Network","Netname","Country","Name","Attempts" >$outfile
sort < $tmpfile >>$outfile
