Operating System - HP-UX
1777430 Members
2875 Online
109070 Solutions
New Discussion юеВ

Re: How do I scan all root mail as it arrives w/ a script?

 
SOLVED
Go to solution
Dave Johnson_1
Super Advisor

How do I scan all root mail as it arrives w/ a script?

I have a need to scan every email as it arrives in root mail for delivery errors and forward some diag information to my Outlook email account and/or my pager. How do I setup to have a script run against each email as it comes in?
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: How do I scan all root mail as it arrives w/ a script?

Okay, root email is kept in a single file:

/var/mail/root

Scanning it is a simple matter.

cat /var/mail/root | grep -i error

This can be made more efficient, but its the basis for what you want to do.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mel Burslan
Honored Contributor
Solution

Re: How do I scan all root mail as it arrives w/ a script?

I think procmail is what the doctor is ordered for your symptoms. You can get it from:

http://hpux.cs.utah.edu/hppd/hpux/Networking/Mail/procmail-3.22/

Hope this helps
________________________________
UNIX because I majored in cryptology...
Doug O'Leary
Honored Contributor

Re: How do I scan all root mail as it arrives w/ a script?

procmail is what you want. You can set up any number of actions based on what's in the mail headers, body, or both.

In fact, there's a reasonably good spam filter called spambouncer that uses procmail rules.

Docs are reasonably good. If you need additional help with it, you can post a question to nntp:comp.mail.misc; however, there are quite a few trolls on that newsgroup so be aware of that up front.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Geoff Wild
Honored Contributor

Re: How do I scan all root mail as it arrives w/ a script?

You might be able to modify the attached script - I use it to purge email...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Bill Hassell
Honored Contributor

Re: How do I scan all root mail as it arrives w/ a script?

I think what you want is for each new message sent to a specific user such as pagermail@server.com to schedule a script which reads the email as stdin so you can process each message in realtime, correct? If so, the answer is as simple as /etc/mail/aliases. Add an entry in aliases like this:

alias_name : | "/fullpath/name options"

or as an example:

pagermail : | /root/bin/pagermail

NOTE: the script must be readable and excutable by the sendmail and rmail daemons. For testing, ehe message can be printed by simply putting a cat | lp in your script. The headers are always first and separated from the body of the message by a single blank line.

Debugging these types of scripts is interesting because there won't be any place for error messages to be viewed (other than mail.log) so I typically put debug messages into the script using logger and then look in syslog. Or you can send debug messages to a specific file.


Bill Hassell, sysadmin
Dave Johnson_1
Super Advisor

Re: How do I scan all root mail as it arrives w/ a script?

Procmail is the solution. After reading all the doc that came with it, and reading Nancy McGough's faq (which the mail-server never did send me), I was able to get it running for a non-priv user. I still need to get the setup working as I need it for root, but I am well on my way now.
Thank you!
-Dave