sed question

Karl Auer kauer at biplane.com.au
Sat May 22 09:03:48 UTC 2010


On Sat, 2010-05-22 at 10:47 +0200, Johnny Rosenberg wrote:
> 2010/5/21 Karl Auer <kauer at biplane.com.au>:
> > On Mon, 2010-05-10 at 10:25 +0200, Amedee Van Gasse wrote:
> >> The problem must be with sed, because if I change (add or remove) sed
> >> statements, it stops at other lines.
> >
> > The fact that you are missing the last line is suspicious.

> Did someone change the subject line of this thread? What was the original line?
> Because the text above is the only text I got on this subject (one
> message only).

I hit "reply to list".

Here's the original I replied to, from Amedee Van Gasse
<amedee at vangasse.eu>:

Hello,

I'm using the following script to have a quick view of all mails that
are refused on my mailserver. It runs inside a screen session. It's my
intention to do some more "pretty printing" later.


#! /bin/bash -e
LOGFILE=/var/log/mail.log
tail -F --lines=1000 --max-unchanged-stats=5 $LOGFILE | egrep NOQUEUE |
sed 's/ localhost postfix\/smtpd\[[0-9][0-9]*\]: NOQUEUE://g' | sed 's/;
/\
     /g' | sed 's/ to=/\
    &/' | sed 's/ proto=/\
    &/' |sed 's/ helo=/\
    &/'


Explained:
* follow the last 1000 lines in mail.log
* show only the lines with NOQUEUE (bounced) emails
* remove hostname & postfix process
* replace ; with newlines
* also put to=, proto= and helo= on a new line


This gives an output like this:

May 10 06:14:02 reject: RCPT from unknown[211.49.70.200]: 550 5.1.1
<an.2006.08.28.19.53.55.655407 at amedee.be>: Recipient address rejected:
User unknown in local recipient table
     from=<an.2006.08.28.19.53.55.655407 at amedee.be>
     to=<an.2006.08.28.19.53.55.655407 at amedee.be>
     proto=SMTP
     helo=<wolfnote>
May 10 06:23:46 reject: RCPT from unknown[124.60.248.25]: 554 5.7.1
Service unavailable
     Client host [124.60.248.25] blocked using bl.spamcop.net
     Blocked - see http://www.spamcop.net/bl.shtml?124.60.248.25
     from=<entitiesqt4 at kapeit.com>
     to=<amedee at amedee.be>
     proto=ESMTP
     helo=<BNQCQDLE>


My problem is that this script doesn't show all lines. The last piece of
output is:

May 10 06:23:46 reject: RCPT from unknown[124.60.248.25]: 550 5.1.1
<amedeen at amedee.be>: Recipient address rejected: User unknown in local
recipient table
     from=<entitiesqt4 at kapeit.com>
     to=<amedeen at amedee.be>
     proto=ESMTP
     helo=<BNQCQDLE>
May 10 06:24:57 reject: RCPT from unknown[186.82.82.124]: 554 5.7.1
Service unavailable
     Client host [186.82.82.124] blocked using bl.spamcop.net
     Blocked - see http://www.spamcop.net/bl.shtml?186.82.82.124

The original is:

May 10 06:23:46 localhost postfix/smtpd[28098]: NOQUEUE: reject: RCPT
from
unknown[124.60.248.25]: 550 5.1.1 <amedeen at amedee.be>
: Recipient address rejected: User unknown in local recipient table;
from=<entitiesqt4 at kapeit.com> to=<amedeen at amedee.be> proto=
ESMTP helo=<BNQCQDLE>
May 10 06:24:57 localhost postfix/smtpd[28098]: NOQUEUE: reject: RCPT
from
unknown[186.82.82.124]: 554 5.7.1 Service unavailable; Client host
[186.82.82.124] blocked using bl.spamcop.net; Blocked - see
http://www.spamcop.net/bl.shtml?186.82.82.124;
from=<boatswainst at withallmyheartchildcare.com> to=<amedee at amedee.be>
proto=ESMTP helo=<Dynamic-IP-1868282124.cable.net.co>
May 10 06:24:57 localhost postfix/smtpd[28098]: NOQUEUE: reject: RCPT
from
unknown[186.82.82.124]: 550 5.1.1 <amedeen at amedee.be>: Recipient address
rejected: User unknown in local recipient table;
from=<boatswainst at withallmyheartchildcare.com> to=<amedeen at amedee.be>
proto=ESMTP helo=<Dynamic-IP-1868282124.cable.net.co>


The problem must be with sed, because if I change (add or remove) sed
statements, it stops at other lines.

So what is going on here? Am I running into limitations of sed?

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)                   +61-2-64957160 (h)
http://www.biplane.com.au/~kauer/                  +61-428-957160 (mob)

GPG fingerprint: B386 7819 B227 2961 8301 C5A9 2EBC 754B CD97 0156
Old fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF





More information about the ubuntu-users mailing list