Nov
14

Command Line via Email

Filed under: Asides | November 14th, 2005
Post

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)

26 Responses

Avatar

Remi | November 14th, 2005 @ 2:14 pm

Well said! :)

Current score: 0
Avatar

jaseone | November 14th, 2005 @ 2:15 pm

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.

Current score: 0
Avatar

Manuzhai | November 14th, 2005 @ 2:29 pm

Hmm, I thought about doing it over IM… Would seem more useful.

Current score: 0
Avatar

Lou | November 14th, 2005 @ 2:33 pm

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?

Current score: 0
Avatar

Robert Deaton | November 14th, 2005 @ 2:43 pm

http://codewar.net/cuts/
This is actually designed for cell phones, but will work just as well with plain e-mail addresses I believe. Try it out, works great from my cell, nice for giving the server a kick on the go.

Current score: 0
Avatar

matt w | November 14th, 2005 @ 2:50 pm

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).

Current score: 0
Avatar

Nick | November 14th, 2005 @ 3:18 pm

Stranger things exist ! ;)

Current score: 0
Avatar

Ozh | November 14th, 2005 @ 3:43 pm

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)

Current score: 0
Avatar

Daniel | November 14th, 2005 @ 5:57 pm

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.

Current score: 0
Avatar

Dolmen | November 14th, 2005 @ 7:20 pm

I remember to have used procmail for such kind of tasks about ten years ago.
http://www.procmail.org/

Current score: 0
Avatar

ryan king | November 14th, 2005 @ 7:35 pm

Email is the universal API.

Wrong. The command line is the universal API.

Current score: 0
Avatar

Mathias | November 14th, 2005 @ 11:59 pm

Fix that typo please, it’s hurting my eyes.

Current score: 0
Avatar

Roy Schestowitz | November 15th, 2005 @ 12:53 am

If you are thinking of mucking about with your server/s from a Treo, do not use E-mail. Wrong tool for a simple task.

http://www.sealiesoftware.com/pssh/

Hope it helps…

Current score: 0
Avatar

Matt | November 15th, 2005 @ 1:06 am

I’m mostly on a Blackberry these days.

Current score: 0
Avatar

Roy Schestowitz | November 15th, 2005 @ 1:19 am

For that you might have to pay:

http://www.idokorro.com/imssh.html

That’s the chance you take when steering away from Open Source. Palm may not be Open Source-oriented, but its users’ ideaology differs.

Current score: 0
Avatar

Matt | November 15th, 2005 @ 1:22 am

$95?!

Current score: 0
Avatar

wantmoore | November 15th, 2005 @ 1:17 pm

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.

Current score: 0
Avatar

Adam | November 16th, 2005 @ 6:08 am

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

Current score: 0
Avatar

Andrei B | November 16th, 2005 @ 3:04 pm

Use a web page to send commands and get results.

The web is the universal API :) Ajax could to a part in this.

Current score: 0
Avatar

Shanti | November 17th, 2005 @ 2:05 pm

I thought MFC was the universal API.

Current score: 0
Avatar

João Sena Ribeiro | November 18th, 2005 @ 12:30 am

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…

Current score: 0
Avatar

Roy Schestowitz | November 18th, 2005 @ 1:03 am

MFC? *LOL*. Probably XML-RPC.

Current score: 0
Avatar

N8Tbb | November 21st, 2005 @ 9:44 am

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

Current score: 0

Share your thoughts