View Script Output Over SSH?
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?
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?
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.
精彩评论