process incoming mail text as a command.
Hal Burgiss
hal at burgiss.net
Fri Feb 12 02:25:54 UTC 2010
On Fri, Feb 12, 2010 at 10:59:50AM +0900, Tomoki Taniguchi wrote:
> I want a way to send an email to a server and have it process the content as
> a command.
procmail does this nicely.
> 1) I want it to check the email address of the sender (possibly other
> email header criteria for more security)
> 2) limit the commands it will process to a predefined list (ie, reboot)
I use a similar trick for openning holes in a firewall when I'm travelling.
See man procmail and man procmailrc, if not familiar with it. Its regular
expression based, and you might have to do some minor fiddling on the server
to get it to process mail with procmail.
:0 BH
* ^From:.*$emailaddress_here
* command: # email contains line like: 'command: reboot'
* ? /usr/local/bin/yourscript.sh
Now there may be other ways of doing this, but the body of the email will come
into the script as STDIN in my experience, which you can grab like:
# strip out the command
command=$(cat /dev/stdin | grep -i command: |sed 's/.* //' | whatever else)
There may be a swifter way of handling this, but this definitely can be made
to work.
I would let the script handle the logic of which commands it is allowed to run
via some kind of whitelist mechanism, and maybe some other sanity checks if
you are doing stuff like rebooting.
--
Hal
More information about the ubuntu-users
mailing list