0

CENTOS 5.x | Sendmail

Hello All,

I hope this is a simple question. =) I need to generate a report summary of messages that triggered a specific DSN code. For example:

Jan 11 07:43:34 server-example sendmail[12732]: p937blksdh3: to=<[email protected]>, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=102537, relay=mta.recipientdomain.com. [12.34.56.78], dsn=5.7.1, stat=Service unavailable

Normally, I would just grep for this information (something like: grep -i "dsn=5.7.1" /var/log/maillog). But the problem is that this only returns a line like above and doesn't tell me the sender of the message.

Ideally, I'm looking for a one-liner that can do the following:

  1. Search sendmail maillog for specific DSN.
  2. Identify the message-id for the email. (I'm guessing awk '{print $}' would be used?)
  3. Return the message details for each (presumably grepping for the the message id retrieved from step 2).

I'm a n00b at scripting/one-liners so I'm sure there's probably an easier way to do this. Any thoughts?

Thanks,

-M

2 Answers 2

1

The following will search for your dsn and if it matches dsn=5.7.1 it will print the msg-id and the sender:

awk '{if($13 ~ /dsn\=5\.7\.1/)print $11 $7}' < /var/log/maillog

I'm not really sure what specific data you're trying to extract other than the msg-id and sender, but you could switch the print $11 $7 fields ($11 $7) by manually counting the fields delimited by white space to select what you want.

Is this what you were after?

Eric

0

Not very efficient (2 scans of the logfile), but should do the trick:

awk '/dsn=5.7.1/ {print $6}' /var/log/maillog|while read ID; do awk "/$ID.*from=/ {print \$7}" /var/log/maillig; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .