Operating System - HP-UX
1833143 Members
3288 Online
110051 Solutions
New Discussion

Email Trigger to Run a Shell Script

 
Alzhy
Honored Contributor

Email Trigger to Run a Shell Script

Anyone got a sample looper or cron runnable script handy that is triggered by an email to the UNIX account that runs the script?

I have a somewhat long running script that currently is run at 5AM in the morning but during the day may required to run in order to present more current data. I am thinking of having this event to be triggered by email.
Hakuna Matata.
3 REPLIES 3
Steven E. Protter
Exalted Contributor

Re: Email Trigger to Run a Shell Script

Still waiting on that email btw.

ls -1 /var/mail > /tmp/datafile

while read -f filename
do
num=$(cat $filename | grep trigger_phrase)
if [ $num -ge 1 ]
then
/usr/contrib/bin/shellscript
fi
num=0
done < /tmp/datafile

This will scan the contents of all the mail accounts. You can modify it to check the contents of one particular mailfile.

Don't forget to set a PATH before using this code in cron.

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
Alzhy
Honored Contributor

Re: Email Trigger to Run a Shell Script

SEP.

I have not forgotten ... it should come to you soon.

BTW, your suggestion is precisely what I have currently but I need something that actually invokes mail/mailx so I can search for a particular subject and even do validation/confirmation etc.

Nelson
Hakuna Matata.
Kevin Shaughnessy
New Member

Re: Email Trigger to Run a Shell Script

I would have the script get triggered by the users .forward file, as in:

\kevin, "|/home/kevin/bin/my_mail_exec"

The first entry keeps the mail in my inbox, the second passes all mail to the script. That script should establish the environment it needs to run, and parse the mail to see if it is the expected trigger.

man 5 aliases