-1

I have a python script that is running on my site \ webhosting. I've activated it by going to the url -> script.py. Is there a way to watch the logs the script outputs the way you'd see in the terminal if you'll SSH -> run python script.py ?

2 Answers 2

1

You can use the 'tee' command, which will output to both stdout (i.e. your SSH terminal) and a file at the same time.

python foo.py | tee /tmp/foo.log

Man page: http://www.computerhope.com/unix/utee.htm More 'tee' examples: http://linux.101hacks.com/unix/tee-command-examples/

Edit: I've just re-read your question. Unless your script actively logs to a file, there's no way of viewing the output. If it does, you can use the -f flag of the 'tail' command over SSH to automatically show additions to the file:

tail -f /tmp/foo.log

Combine this with a 'screen' session, and you can monitor the output and reconnect whenever is convenient. Screen documentation: http://www.cyberciti.biz/tips/how-to-use-screen-command-under-linux.html

0

Adding the raw_input() at the end of your script will force you to hit enter before the script executes. Then it will show the output in the terminal window. Just remember to take it out when you're done your initial testing.

Or you could output your Python script to a file then just tail that file. Which would be the easiest way.

python foo.py > file
3
  • I like your second option better. How can I direct the output of the script into a file and tail it? (new to python..)
    – Segev
    May 14, 2013 at 22:50
  • @EXEC_BAD_ACCESS updated the answer for you. May 14, 2013 at 22:54
  • Maybe my question wasn't clear enough. I already started the script through a url directing to the script. 5 hours later I want to see the outputs of the script in real time. Your solution would work only with SSH and there I can already see what's going on through the terminal window
    – Segev
    May 14, 2013 at 22:57

Not the answer you're looking for? Browse other questions tagged .