Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to trigger my python script remotely, but don't really want to expose any Web or other interface, eg. I need some passive way. One of the ways I can think of is by sending e-mail, then server can receive it and run the script. It is highly desirable to have an open console window on Ubuntu and then run the script, so I can see the output and progress if it lasts long and I will have direct access to it. But if not possible, then only running script would be enough, I'll think how to redirect output into file.

share|improve this question

2 Answers 2

procmail is one way to automatically run a script when e-mail gets received. Another way is to define a new mail alias, say, somenameyouwant@yourdomain.com and make that just run a script. For example, in Postfix you would put to aliases something like

somenameyouwant@yourdomain.com  "|screen python your_script.py"

Then just add necessary safe belts to your Python script so it won't automatically execute the software every time a new mail arrives to that box; make the script examine the mail body for keywords, or do something else.

Screen, what's that? Good old screen is here to help you for your monitoring needs. Just run your script with

screen python your_script.py

Then you can login to your server and attach to that screen with

screen -rd

and when you are done watching progress, press Ctrl+a-d to detach the screen and leave it running.

share|improve this answer
    
but I don't have remote access to Ubuntu box when first running it. First task is to run it via e-mail. Second task is to somehow run it on console window. –  Michael Aug 2 '11 at 9:10
    
Edited my reply a bit. Just run the screen from procmail or Postfix aliases? –  Janne Pikkarainen Aug 2 '11 at 9:12

procmail is the usual way of approaching this. Set it up for a specific user, write the relevant procmail recipe and then mail to that user can trigger anything you like.

Some people will suggest alternatives to procmail since it hasn't been in active development for quite some time - however, it also works very well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.