[PLUG] Execute Script Via Email

wes plug at the-wes.com
Thu Jan 21 19:33:05 UTC 2021


On Thu, Jan 21, 2021 at 9:06 AM Michael Barnes <barnmichael at gmail.com>
wrote:

>
> I need a given script to execute based on what is in
> either the Subject or Body of the email. For example, I send an email to
> machine at somewhere.com with something like RESTART_FOO in the Subject or
> Body and it would run the script RESTART_FOO. Another email sent to the
> same address may say RESTART_BAR and execute that script.  From what I
> understand, procmail simply reacts to an incoming email, regardless of what
> is in that email.
>

What MTA are you using? Most of the big ones support directing emails to an
arbitrary executable on the system via the | directive. This is, of course,
terribly insecure so you may have to jump through hoops to enable this
behavior. I had quite an adventure getting it to work in exim, but it does
indeed work.

If the address for this was command at example.tld, /etc/aliases would contain:

command: "|/usr/local/bin/command-processor"

/opt/command/processor would be a shell script that looks for the key
values like RESTART_whatever and then takes action based on that input.

-wes



More information about the PLUG mailing list