Operating System - HP-UX
1753838 Members
9044 Online
108806 Solutions
New Discussion юеВ

Call a script whenever I receive an email

 
SOLVED
Go to solution
David L Brewster
Frequent Advisor

Call a script whenever I receive an email

I want to be able to run a script every time I receive an email. (Don't ask why).

I am assuming that I would need to modify my /etc/mail/aliases file.
Currently, it looks like this:
brewsted : brewsted@uspsy14ts

I've tried:
brewsted : brewsted@uspsy14ts, /users/brewsted/bin/myscript.ksh

But it doesn't seem to call the script, but I do get an email.

I've also tried:
brewsted : brewsted@uspsy14ts | /users/brewsted/bin/myscript.ksh

But that too yielded the same results.

I am on HP-UX 11.11

Thanks for your help,
Dave
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: Call a script whenever I receive an email

Hi Dave:

A classic way to handle this is to have a '.forward' file in your ${HOME} directory. The file can look like:

brewsted, |/users/brewsted/bin/myscript.ksh

In this case when you receive a mail the script will be run too.

Regards!

...JRF...
David L Brewster
Frequent Advisor

Re: Call a script whenever I receive an email

Ok, thanks. Thats a great start.
While I work on getting that going...
What I want to do the same kind of thing for a user that is not a user on our mail server?
Zinky
Honored Contributor

Re: Call a script whenever I receive an email

James,

Any trick too to only watch for certain SUBJECT strings and SENDER/SOURCE to trigger a script?

Thanks.

David... apologies for hi-jacking this thread.
Hakuna Matata

Favourite Toy:
AMD Athlon II X6 1090T 6-core, 16GB RAM, 12TB ZFS RAIDZ-2 Storage. Linux Centos 5.6 running KVM Hypervisor. Virtual Machines: Ubuntu, Mint, Solaris 10, Windows 7 Professional, Windows XP Pro, Windows Server 2008R2, DOS 6.22, OpenFiler
Steven E. Protter
Exalted Contributor

Re: Call a script whenever I receive an email

Shalom Dave,

good email utility script, does attachments.

http://www.hpux.ws/?p=7

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
James R. Ferguson
Acclaimed Contributor
Solution

Re: Call a script whenever I receive an email

Hi (again) Dave:

> What I want to do the same kind of thing for a user that is not a user on our mail server?

I assume by this that you want to also forward email to another server. You could define the 'DS' (smart relay) macro in '/etc/mail/sendmail.cf' like:

DSmymailserver.mycompany.com

Then, in your '.forward' file you might have:

# cat /home/brewsted/.forward
\brewsted,brewsted@youraddress.com,"|/users/brewsted/bin/myscript.ksh"

Notice that a backslash is used if you include your own account as a mail recipient. Notice too that the script to run is enclosed in double quotes. I failed to do that in my first post :-(

Regards!

...JRF...
David L Brewster
Frequent Advisor

Re: Call a script whenever I receive an email

Bingo JRF, Bingo.

I have the following in my /etc/mail/aliases file:
brewsted : brewsted@uspsy14ts, "| /users/tech/jobs/systems/mail_test.ksh"

Works just as I need it to.
I tried a lot of combinations on my own, but the double quotes seem to have been the key.

Thanks for your help!

Dave
David L Brewster
Frequent Advisor

Re: Call a script whenever I receive an email

Go Phillies!