Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. [], 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?

share|improve this question
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
up vote 2 down vote accepted

In bash

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



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?

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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