Command Line via Email

Silly idea of the day — I want a script that listens on a secret email address and executes commands I send it via email, and then emails me back the results. Email is the universal API.

26 thoughts on “Command Line via Email

  1. Actually wouldn’t be too hard to setup, one of the wp-mail mods (ketai I think) does something similar by piping the email to a script to publish the moblog so it is a push instead of a pull from wp-mail via a cron or wp-cron job. I was always meaning to implement something like that myself for my own moblogging but now Flickr is taking care of all that for me.

    It would just be a matter of modifying the script to run other commands based upon the content of the email, although of course you would want to be real careful about protecting against malicious emails just in case someone found out the secret email.

  2. I actually have a business idea dependent on the ability to trigger scripts over email. I came up with a week ago so I haven’t investigated yet. Anyone?

  3. Pipe an email address into a php script and shell_exec it? Of course … you’d be running the script as ‘nobody’ unless you use phpsuexec I believe which would make permissions a bit weird and whatnot, but … it’d probably work (and you’d be able to do all kinds of custom stuff since you’re already good at PHP).

  4. Actually not silly at all, I’ve been using something like this for about two years, very handy when behind a slow and filtering corporate firewall (mostly to wget stuff and get them sent me back)

  5. You can do this with the smrsh shell from sendmail on linux/unix.
    Create a new user on your system. ex: secret_email (change this to your secret email address)

    edit /etc/aliases and add a line:

    secret_email: “|/etc/smrsh/script_name”

    then run “newaliases”

    Then create a script called script_name, or whatever in /etc/smrsh
    Once the server recieves an email to this account, it can do whatever the script dictates.

    I have a working script in Python, just email me for it, unless is it okay to post in the comments.
    The script searches the incoming mail for a line like , and parses out the command and spawns a child process to run it. The stdout is then captured, and returned to an email address you specify.

  6. Ryan King: Wrong. The command line is the universal API.

    I think Matt is right actually. No doubt the CLI is great if you’re on a *nix system, but with so many different platforms out there today, Email is about the ONLY thing that works exactly the same across all of them.

  7. The book multitool linux has a whole section looking at how to do this. It’s also a great book for ideas re: linux solutions. Probably not aimed at someone with as much experience but I found it useful and interesting

  8. I remember from the old BBS days, when I dindn’t have Internet access, to use FTP via e-mail (actually, FidoNet netmail, at the time).

    One would issue commands (like directory listings) and get the command results in another message. When you’d like to download a file, the file would be sent to you as an attachment or something like that.

    It was my first kind of Internet access…

  9. Ah yes, the days of DOS, FIDONet, Mustang Wildcat…those were the days. Everything was command line! You were in control and was a lot less work as you didn’t have to search for everything. Question: Has anyone had any luck with a command line interface for Novell GroupWise? Seems they have the SMTP server so restricted here that you can’t even alert you phone for your next meeting!!! Thanks