2

I have a script, called test.py, that does the following:

while (1):

....print "hello world"

(this script simply prints 'hello world' continuously).


Now, I am using two machines (machine A and machine B). Same user is used for both machines. I would like to do the following:

(1) [working with machine A] run test.py programatically on machine A { meaning, a local python script will be running test.py using say os.system(....) } ( at this point, the script test.py is printing "hello world" to the screen of machine A )

(2) [working with machine B] I now want to log in into machine A using ssh and 'view' the output of the script that we ran in (1)

How do I achieve this? I know how to write the script that will be running and starting test.py on machine A. I also know how to ssh from machine B to machine A.

What I don't know is:

(*) What command should I use in (1) in order to run the python script so that its output can be easily viewed while logging from a different machine (machine B) to machine A?

(*) Following the ssh from machine B to machine A, how do I 'navigate' to the screen that shows the output of test.py?

2 Answers 2

4

There are a few ways you could do this… But possibly the simplest would be a fifo buffer:

A$ mkfifo /tmp/stuff
A$ ./test.py &> /tmp/stuff

Then on machine B:

B$ ssh A "cat /tmp/stuff"
hello world
hello world
...

Normally I would suggest using screen, but it assumes that you're going to be running from inside a terminal (which would be tricky). I've heard that detach is supposed to be simpler, so possibly you could try that?

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you David. I know 'screen' is used from the terminal. is it possible to use 'screen' from within the python script?
That… Would probably be tricky. Because screen does all sorts of terminal magic to write text in the right place and let you switch between screens and stuff. If a fifo buffer or redirecting to a file isn't good enough, I'd look at using detach before screen.
1

A very quick alternative is to pipe the output of your python program to a file, and then simply using tail with the second user to see the output as it's being written to the file. However, with a program like you have there, the file will very quickly become massive.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.