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.

We have an external system which happens to fail from time to time. We don't have direct access to the logs of this system, all we get are daily status mails delivered to our Inbox indicating failure or success. Now what we're trying to achieve is counting failure and success messages to somehow measure reliability.

If we would have access to the logs, this would be fairly easy using grep and wc and that kind. But all we have is a bunch of mails.

Now heres the question: Can somebody come up with way to connect to an imap-server, go to a specific folder, get all messages and count a certain string? (preferably bash, python or perl). We don't expect the exact command. Some ideas to get us started would be great.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I'd use Python and imaplib. This imaplib example connects to a mailbox and retrieves all messages. The message body is available in that loop, so you could do whatever pattern-matching you wanted to on it. You could even just (albeit wastefully) just run this script and use your familiar tools on it. (I say "albeit wastefully" because the example scripts reads all messages in the mailbox every time it runs.)

share|improve this answer
    
That's exactly what I was looking for. imaplib looks great. –  toString Aug 21 '10 at 7:43

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.