I have written a bash script to to sort the data from logs i need some help in printing the outputs , i dont have much ideas in bah scripting.
Sample script
-----------------------
#!/bin/bash
a=`date | cut -d " " -f2,2,3`
cat /var/log/maillog |grep "$a" |grep -E -e 'deferred|bounced' >> /tmp/mailer
for i in `cat /tmp/mailer`
do
address=`echo $i|awk -F " " '{print $7}' /tmp/mailer`
result=`echo $i|awk -F " " '{print $12}' /tmp/mailer`
reason=`echo $1|awk -F " " '{print $17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$28,$29}' /tmp/mailer`
echo "$address $result $reason"
done
Present output
----------------------------
the email send to=<mhillers@bellsouth.net>, status=deferred talk to me: 521-75.126.169.21 blocked by ldap:ou=rblmx,dc=att,dc=net 521 Error - for abuse.
the email send to=<timber'lee@timberlee.com>,status=deferred timeout (#4.4.2) (in reply to end of DATA command))
the email sendto=<apache@bikepartsusa.com>,status=bounced The email account that you tried to reach does not Please try
I want and output Like this any Ideas
mhillers@bellsouth.net status=deferred Error - for abuse
timber'lee@timberlee.com status=deferred timeout
apache@bikepartsusa.com email account that you tried to reach does not
---------- Post updated at 04:49 PM ---------- Previous update was at 04:44 PM ----------
I am sending the log format i have
/var/log/maillog
Jan 19 12:21:10 bikepartsusa postfix/smtp[6054]: 4DD75D4C45: to=<rfgoodman@bellsouth.net>, relay=gateway-f2.isp.att.net[207.115.11.16]:25, delay=155893, delays=155892/0.01/0.2/0, dsn=4.0.0, status=deferred (host gateway-f2.isp.att.net[207.115.11.16] refused to talk to me: 521-75.126.169.21 blocked by ldap:ou=rblmx,dc=att,dc=net 521 Error - Blocked for abuse. Contact abuse_rbl@abuse-att.net.)
Jan 19 12:29:30 bikepartsusa postfix/smtp[6756]: 57986D4C53: to=<apache@bikepartsusa.com>, relay=ASPMX.L.GOOGLE.com[74.125.159.27]:25, delay=3.5, delays=0.01/0/0.3/3.1, dsn=5.1.1, status=bounced (host ASPMX.L.GOOGLE.com[74.125.159.27] said: 550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1 'This Gmail user does not exist...' - Gmail Help g9si15796109anh.79 (in reply to RCPT TO command))
Jan 19 12:21:31 bikepartsusa postfix/smtp[6055]: 9E874D4C43: to=<timber'lee@timberlee.com>, relay=nullmx.timberlee.com[209.181.247.105]:25, delay=423999, delays=423979/0.01/0.08/20, dsn=4.0.0, status=deferred (host nullmx.timberlee.com[209.181.247.105] said: 451 timeout (#4.4.2) (in reply to end of DATA command))