Tuesday, October 13, 2009

[ Linux ] Postfix Log Analyzer for dead addresses

#!/bin/bash
# This system filters the current maillog or mail.log and provides data on what email addresses are bad!

logs=`for logfile in /var/log/mail{.,}log; do if [ -f $logfile ]; then echo $logfile; fi; done` && echo $logs
add_log=/root/bounces.txt
rec_log=/root/bounce_record.log

if date | grep Sat | grep "21:1" >/dev/null;
then
{
gunzip mail.log.*.gz

echo "Starting : `date`" >> $rec_log

egrep -i '(Not\ a\ valid\ mailbox|User\ is\ unknown|Undeliverable\ address|recipient\ rejected|user\ unknown|invalid\ recipient\:|address\ rejected|Does\ not\ exist|Illegal\ alias|mailbox|Mailbox\ is\ inactive|reach\ is\ disabled|Mailbox\ disabled )' $logs | egrep -v -i '(policy|spam|grey?list|sender|dns|spf\ record|reverse|quota|acces\ denied|unavail|later|try|headach|temporar|full|too\ many|root|esozm)' | grep "@" | awk '{print $7}' | grep -v "host" >$add_log
   
echo " Tabulating amount of records: " >> $rec_log

egrep -i '(Not\ a\ valid\ mailbox|User\ is\ unknown|Undeliverable\ address|recipient\ rejected|user\ unknown|invalid\ recipient\:|address\ rejected|Does\ not\ exist|Illegal\ alias|mailbox|Mailbox\ is\ inactive|reach\ is\ disabled|Mailbox\ disabled )' $logs | egrep -v -i '(policy|spam|grey?list|sender|dns|spf\ record|reverse|quota|acces\ denied|unavail|later|try|headach|temporar|full|too\ many|root|esozm)' | grep -c "@" >>$rec_log

echo "Finishing : `date`" >> $rec_log
echo "dun dun dun done"

}
else
{
echo "Not time to process the mail logs"
}
fi

No comments: