Help with Email Status shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Email Status shell script
# 1  
Old 01-19-2011
Help with Email Status shell script

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
-----------------------
Code:
#!/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 ldapSmilieu=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 ldapSmilieu=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))
# 2  
Old 01-19-2011
OK you should probably start by extracting the 3 data fields you need from the log (toemail, status and errorstr):

Code:
awk '
   /to=/&&/, status=.* \(/ {
   toemail=gensub(".* to=<(.*)>.*", "\\1", $0);
   status=gensub(".*, status=([^ ]*) .*", "\\1", $0);
   errorstr=gensub(".*, status=[^ ]* \\((.*)\\)$", "\\1", $0);
   print toemail, status, errorstr
} ' /var/log/maillog

It then looks like you want to suppress display of the bounced status and transpose/convert the errorstr.

The errorstr seems to be quite free format and I suspect there are a many more types of errorstr than you example data lists so I've left the string as it appears in the original logfile. Perhaps you can give us some more indication on what should happen with this string.
# 3  
Old 01-20-2011
i am getting an error when i execute this directly can

[root@freebsd:/root 01:42]sh test2.sh
awk: calling undefined function gensub
input record number 1, file /var/log/maillog
source line number 3

---------- Post updated at 03:26 PM ---------- Previous update was at 03:17 PM ----------

My present out put is like this i need it to setup the script in a single line

to=<mhillers@bellsouth.net>,
to=<skimmels@bellsouth.net>,
to=<rfgoodman@bellsouth.net>,
status=deferred
status=deferred
status=deferred
timeout (#4.4.2) (in reply to end of DATA command))
The email account that you tried to reach does not Please try
#5.1.0 Address rejected www@www.unitedlabsupplies.com (in reply to RCPT TO command))

output should be like this

mhillers@bellsouth.net status=deferred Error - for abuse

please help me i creating my first script
# 4  
Old 01-20-2011
OK you don't have gnu awk this should be equilivent:

Code:
awk '
   /to=/&&/, status=.* \(/ {
   toemail=$0;
   status=$0;
   errorstr=$0;
   gsub(".* to=<", "", toemail);
   gsub(">.*", "", toemail);
   gsub(".*, status=", "", status);
   gsub(" .*", "", status);
   gsub(".*, status=[^ ]* \\(", "", errorstr);
   gsub("\\)$", "", errorstr);
   print toemail, status, errorstr
} ' /var/log/maillog

# 5  
Old 01-20-2011
the present output will not help me it similar to log i need only email id status the a small reason
present output
-------------------
mhillers@bellsouth.net deferred host gateway-f2.isp.att.net[207.115.11.16] refused to talk to me: 521-75.126.169.21 blocked by ldapSmilieu=rblmx,dc=att,dc=net 521 Error - Blocked for abuse. Contact abuse_rbl@abuse-att.net.
www@www.unitedlabsupplies.com bounced host smtp.secureserver.net[216.69.186.201] said: 550 #5.1.0 Address rejected www@www.unitedlabsupplies.com (in reply to RCPT TO command)
apache@bikepartsusa.com 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 ogle.com/support/bin/answer.py?answer=6596]'This Gmail user does not exist...' - Gmail Help g9si15796109anh.79 (in reply to RCPT TO command)

i need an output like this

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
# 6  
Old 01-20-2011
Code:
awk '
   /to=/&&/, status=.* \(/ {
   status="status=deferred";
   toemail=$0;
   errorstr=$0;
   gsub(".* to=<", "", toemail);
   gsub(">.*", "", toemail);
   gsub(".*, status=[^ ]* \\(", "", errorstr);
   gsub("\\)$", "", errorstr);
   if(index(errorstr, "abuse")) errorstr="Error - for abuse";
   if(index(errorstr, "not exist")) { 
      status="email" ; 
      errorstr="account that you tried to reach does not"
   }
   if(index(errorstr, "timeout")) errorstr="timeout";
   print toemail, status, errorstr
} ' /var/log/maillog


Last edited by Chubler_XL; 01-20-2011 at 08:53 PM..
# 7  
Old 01-21-2011
Thank`s for great help i need to parse a few more log files

present output
----------------------
drlarocque@juno.com status=deferred host mx.dca.untd.com[64.136.44.37] refused to talk to me: 550 Access denied...181d58d961d8bdbd296888915959596869c55d0878294c2dbd6d6c5d25ac5d0d55a1d5550decec78b1ecf9852d1 92165196d01080c016d018d4c...
scofieldserco@juno.com status=deferred delivery temporarily suspended: host mx.dca.untd.com[64.136.44.37] refused to talk to me: 550 Access denied...4f5135b57185a9a96160c1a1bd80bda1b9053d592061758da9b0643dcd103d95e984e5e995909020e190241d8d0 0f1f000b0f959c9f9b0f95075...
pgstore@post-gazette.com status=deferred host mailrelay3.post-gazette.com[64.206.167.180] said: 552 Rejected by CA Gateway Security [scm-3.post-gazette.com] (ASF-99) (in reply to end of DATA command)
pgstore@post-gazette.com status=deferred host mailrelay3.post-gazette.com[64.206.167.180] said: 552 Rejected by CA Gateway Security [scm-3.post-gazette.com] (ASF-99) (in reply to end of DATA command)
biostockroom@umbc.edu status=deferred host mxin.umbc.edu[130.85.12.6] said: 451 4.3.2 Greylisting. Try back in a while. (in reply to RCPT TO command)

i would like to parse it
---------------------------------
i wan to parse a few more logs


biostockroom@umbc.edu status=deferred Greylisting
pgstore@post-gazette.com status=deferred host Rejected by CA Gateway Security
scofieldserco@juno.com status=deferred delivery temporarily suspended
drlarocque@juno.com status=deferred host refused to talk to me:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automation script for email alert when a job get complete with status successful.

Guyz, Please let me know about script which is to be sending an automatic email to particular mail id's when a monotoring job get complete with status successful. (1 Reply)
Discussion started by: Rehan Ahmad
1 Replies

2. Shell Programming and Scripting

Shell script has to run until the status value is updated

Hi All, Need some help like how to exit from the script after updating the column in data base. db2 connect to DB STATUS=$(db2 "SELECT STATUS FROM XYZ ) echo $STATUS Initially the status value will be '4' or 'NOT YET RUN'. The Shell script has to run until the status value is updated... (7 Replies)
Discussion started by: sumanmca2006
7 Replies

3. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

4. Shell Programming and Scripting

Help....script check status if see something then send email

autorep -m bogus Machine Name Max Load Current Load Factor O/S Status ___________ ________ ___________ ______ ________ ______ bogus --- --- 1.00 Sys Agent Online Status ______ Online Offline Missing Unqualified The "Status" always "Online". I like create a script execute run... (6 Replies)
Discussion started by: dotran
6 Replies

5. Shell Programming and Scripting

Script to email status

Hi, I have few processes in the server continuous run few jobs, each of the process will generate a log file which detailing when its jobs are completed. the logfile will has the name something like this, result1.log, result2.log, result3.log,.... result10.log, result11.log, result12.log.......... (8 Replies)
Discussion started by: khchong
8 Replies

6. Shell Programming and Scripting

how to suppress the status of fork in shell script

When command is executed by forking, the console displays the status of that command. I want to suppress it.. how to do it ? Example: var1=`date` & echo "hello world"; output: hello world + Done var1=`date` I want to suppress the second line "+ Done var1=`date`". I... (10 Replies)
Discussion started by: Arun_Linux
10 Replies

7. UNIX for Dummies Questions & Answers

Job Status for running shell script

Hello, I am running a shell script whose execution often takes several hours to complete. Is there way I can get some kind of status update as the job is running? Something as simple as the start and the current time stamp. Thanks, Gussi (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

8. Shell Programming and Scripting

return status after run the shell script

Hello, I wanted to delete all files which are placed 14 days back. Here is my below script. My script works very well and it deletes all files 14 days back. I wanted to display message incase if the delete script is not successful. The below script returns always successful. But the directory... (6 Replies)
Discussion started by: govindts
6 Replies

9. Shell Programming and Scripting

status bar in shell script or perl

How To Generate different different progress bar in shell script? like we install some software it show us progress, like we install RPM that also show us progress. Thanks, Bash (2 Replies)
Discussion started by: learnbash
2 Replies

10. Shell Programming and Scripting

check the status and send an email with status

Hi, We have a text file which has the following data. ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183 7~U~00200~000011258~0~P~< GS~FA~EE05J~U1CAD~051227~1831~000011258~X~002002 ST~997~0001 AK1~SH~247 AK2~856~2470001 AK5~A AK2~856~2470002 AK5~A... (3 Replies)
Discussion started by: isingh786
3 Replies
Login or Register to Ask a Question