2

I use Sendmail on CENTOS 5.x, 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=<someuser@recipientdomain.com>, 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).
  • 1
    For those of us who aren't specifically familiar with sendmail, it might help if you post a more complete set of log lines, and describe exactly what details you're paying attention to when you do this manually. For example, in the line you've posted, is p937blksdh3 the message-id? – Jander Jan 22 '11 at 2:59
2

In bash

dsn=5.7.1
$ grep $dsn /var/log/maillog | awk '{print $6}' | awk -F: '{print $1}'

returns:

p937blksdh3

Of the line you posted, I'm guessing that is the message id?

OK, it's not one line. Then grep for that for message details, where are the message details kept?

  • Thanks. That pointed me in the right direction. The final one-liner I came up with is a variation of that and includes a for loop: grep -i "dsn=5" /var/log/maillog | awk '{print $6}' | sed 's/://' | while read -r x; do grep -i "$x" /var/log/maillog; done – Mike B Feb 14 '14 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.