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.
2 Answers
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.

- 31,852
- 4
- 58
- 81
-
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 02 '11 at 09:10
-
Edited my reply a bit. Just run the screen from procmail or Postfix aliases? – Janne Pikkarainen Aug 02 '11 at 09: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.

- 9,311
- 1
- 34
- 46