How can we trigger a shell script on an unix server through an email with particular subject?
+4
A:
procmail allows you to act on incoming mails, including filtering and starting external commands.
Some useful links:
- general procmail documentation: http://pm-doc.sourceforge.net/doc/
- start a shell command as a procmail rule: http://partmaps.org/era/procmail/mini-faq.html#rtfm
Wim
2010-08-09 12:42:16
Can you provide me an URl where the process of doing so is documented.
Arkid
2010-08-09 14:48:31
A:
You could in theory, by writing a program to monitor/poll the incoming email server and check the subject line using standard POP3 protocol, if the subject line has a particular trigger keywords, invoke the shell script... This is the order of approach that would suit... there may be an open source solution already out there...
- Using sockets, connect to the incoming email server by IP and port (usually 25), non-blocking that is not to seize up and chew up CPU time, within a thread looping forever
- List the emails using the POP3 protocol
- Pull down the headers via POP3 protocol and do a regexp on the subject line
- If the regexp matches the subject line, issue a trigger perhaps a system call to invoke the shell script
tommieb75
2010-08-09 12:43:53
+1
A:
More general, but to my mind less useful than Wim's procmail suggestion: You can even just point your .forward
at an executable with "|scrip.sh".
dmckee
2010-08-11 14:50:11
Actually, barring a system-wide procmail install that integrates directly with the mailer, that's how you'd get procmail started in the first place. But if you do use procmail you can leverage its filtering features and avoid having to write the subject filter in your own script.
Wim
2010-08-16 14:33:36