Shell or Perl script to search for a list of text / string & return 1st string of the preceding line
Posted on 2011-03-03
' mailq ' often returns various problem mails : such mails would hog genuine
mails from going thru
I need to search for a list of text / string that's found from "mailq" output
& then the script would return the first value of the line just preceding the
line these text were found.
List of search text / string are (which may be added in future ):
a) "Connection timed out"
b) "lowest numbered MX record"
c) "Connection refused"
d) "Mailbox size limit exceeded"
e) "Undeliverable address"
f) "Network is unreachable"
g) "exceed mailbox quota"
..... this list of search text may grow .....
& based on the sample mailq output below, the script would return the values
. . .
These values are the problem mails' ids & will be passed to postsuper to
be withheld in 'hold' queue :
mailq | script_needed | postsuper -h -
Sample problems mails returned by mailq :
. . . . . .
DD063290F38 2924 Tue Mar 1 10:17:13 firstname.lastname@example.org
(host mail.phins.com.sg[18.104.22.168] said: 452 <email@example.com> Mailbox size limit exceeded (in reply to RCPT TO command))
D8E42291DBE 2919 Tue Mar 1 10:20:43 firstname.lastname@example.org
(connect to ritzmail.RITZ-CARLTON.COM.SG[22.214.171.124]: Connection timed out)
D440F291197 2185 Fri Feb 25 15:15:24 email@example.com
(Host or domain name not found. Name service error for name=GMAIL.COM.SG type=MX: Host not found, try again)
D3E14291D93 3051 Tue Mar 1 10:19:51 firstname.lastname@example.org
(host mailserv.skylightgroup.com[126.96.36.199] said: 452 Message for <email@example.com> would exceed mailbox quota (in reply to RCPT TO command))
9B90CA58AE 1278 Sun Feb 27 15:28:08 firstname.lastname@example.org
(connect to park.goldenname.com[188.8.131.52]: Connection refused)
E7EEBA579E 1272 Sun Feb 27 19:48:56 email@example.com
(host alt1.aspmx.l.google.com[184.108.40.206] said: 450-4.2.1 The user you are trying to contact is receiving mail at a rate that 450-4.2.1 prevents additional messages from being delivered. Please resend your 450-4.2.1 message at a later time. If the user is able to receive