Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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=<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).

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

share|improve this question

2 Answers 2

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

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.