How to have an email message trigger a script

A neat trick you can do with sendmail is to have a script execute whenever a message is received for a certain address.  To do so, add a line similar to this to /etc/mail/aliases:

alias : "|/path/to/"

This uses sendmail's rules syntax which says "If the left side of the colon is true, do what's on the right side."  Note that there need to be spaces on both sides of the colon.  The message received is fed as input into the script, if the script takes input.  For example,

billing : "|/usr/local/send_invoices"

entered into /etc/mail/aliases will cause the send_invoices script to run each time a message is sent to billing@hostname.   (Be sure there's a way a message can get to hostname.)

Remember to run newaliases after making any changes to the aliases file.  Also, make sure the script to be run is world-accessible.