Trigger remote action via email msg

  • Follow


I would like to send an unattended remote unix system a email thats contents 
would trigger a particular action (run a script or program) on receipt of the 
email. The unix system would need to automatically fetch via imap and read the 
email, scan its contents, and perform the action specifed in the contents.

Is this possible using conventional mail programs such as mutt or elm?

-gene
-- 
Lit up like Levy's

0
Reply Gene 12/4/2003 11:23:28 PM

On Thu, 4 Dec 2003, Gene Smith wrote:

GS> I would like to send an unattended remote unix system a email thats contents
GS> would trigger a particular action (run a script or program) on receipt of the
GS> email. The unix system would need to automatically fetch via imap and read the
GS> email, scan its contents, and perform the action specifed in the contents.
GS>
GS> Is this possible using conventional mail programs such as mutt or elm?
GS>

Fetchmail to fetch the mail.
Procmail to parse your email for the keyword somewhere in your email.

Alan

( If replying by mail, please note that all "sardines" are canned.
  There is also a password autoresponder but, unless this a very
  old message, a "tuna" will swim right through. )

0
Reply Alan 12/5/2003 12:52:16 AM


On Thu, 04 Dec 2003 18:23:28 -0500, Gene Smith <gds@chartertn.remove-me.net> wrote:
> 
> 
> I would like to send an unattended remote unix system a email thats contents 
> would trigger a particular action (run a script or program) on receipt of the 
> email. The unix system would need to automatically fetch via imap and read the 
> email, scan its contents, and perform the action specifed in the contents.
> 
> Is this possible using conventional mail programs such as mutt or elm?
> 
> -gene


I'd run a script from a cronjob on the remote machine that looked like this:

#!/bin/sh

fetchmail -s -t 100  # fetchmail covers IMAP and POP

# run fetchmail quietly (no output to console) and give up trying to make
# the connection after 100 seconds.

# assuming an mbox format and one mailbox, grep through that box for the
# string that will cause the script you want to run

if grep '^Subject: XX$iwwq4>%Hqaz' $HOME/Mail/inbox &> /dev/null   
then /usr/local/bin/script
else exit 0
fi

# now remove that line from the mailbox so that it won't trigger the running
# of script again

ed -s $HOME/Mail/inbox <<PPP
g/XX$iwwq4>%Hqaz/d
w
q
PPP

# note that you can't use a "/" in the subject line of the mail, and that
# the cronjob and fetchmail and the script must all be owned by the same
# user.


exit 0



That's ONE way to do it. Hope you find it helpful.


AC

0
Reply Alan 12/5/2003 12:58:55 AM

Looks good, I will give it a try. Thank you so much!
-gene

0
Reply Gene 12/5/2003 3:23:25 AM

3 Replies
257 Views

(page loaded in 0.083 seconds)

Similiar Articles:













7/23/2012 3:17:06 PM


Reply: