1826499 Members
1782 Online
109692 Solutions
New Discussion

piping emails to script

 
SOLVED
Go to solution
jerry1
Super Advisor

piping emails to script

Does anyone have a script to process
email messages thru aliases file e.g.

userid : "| /usr/bin/somescript"
1 REPLY 1
Peter Nikitka
Honored Contributor
Solution

Re: piping emails to script

Hi Jerry,

I think you ask for an example of "/usr/bin/somescript".

In the following part of such a script the whole mail message is caught in a file and the subject and the sending user is analyzed.
Subject must contain the string 'Backup' and a hostname.

...
h4backup=$(tee /tmp/back.req | awk '/^Subject:/ {key=tolower($2);
if (key=="backup") host=$3;exit}
END {if(host) print tolower(host)}')
fromuser=$(awk '/^From: / {$1="";print;exit}' /tmp/back.req)

# Wenn der exit-Status != NULL ist, beschwert sich der sendmail
if [ -z "$h4backup" ]
then
date +%d%b%y-%X" Format der Backupanfrage ungueltig" >>$logfile
print -n "\t\tFrom $fromuser\n\t\t" >>$logfile
if grep '^Subject: ' /tmp/back.req
then :
else print Kein Subject:
fi >>$logfile
exit 0
fi
...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"