I write a lot of command line tools and scripts in Python. Sometimes I need to kick them off remotely. A simple way to do this is to launch a tiny web server that listens for a specific request to start the script.
I add a "WebRequestHandler" class to my script and call it from my main method. There is a "do_something()" method in the class. You call your code from this method.
All you have to do is launch your script and it will sit there and wait for requests. If the request is bad, it spits back a 404 error. If the request path matches what we are looking for (in this case "/foo"), the code is launched.
Now you have an easy way to call your script remotely. Just open a browser and type in the URL: http://your_server/foo, or call it with a tool like 'wget' or 'curl'.
if self.path == '/foo':
print 'hello world'
server = BaseHTTPServer.HTTPServer(('',80), WebRequestHandler)
(this was adapted from a code sample in "Python In A Nutshell" by Alex Martelli)
Copyright © 2006-2008 Corey Goldberg
The opinions expressed herein are my own personal
opinions and do not represent my employer's view in any way.