Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

A friend, using a remote machine, ran a script that SSHed to my machine, and ran the following python script that resides on my machine:


while (1):

....print "hello world"

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

I am now logged in to my machine. How can I see the output of the script my friend was running?

if it helps, I can 'spot' the script my friend is using:


me@home:~$ ps aux | grep justprint.py

**friend 7494 12.8 0.3 7260 3300 ? Ss 17:24 0:06 python TEST_AREA/justprint.py**

friend 7640 0.0 0.0 3320 800 pts/3 S+ 17:25 0:00 grep --color=auto just

what steps should I take in order to view the "hello world" messages on my screen?

share|improve this question

migrated from stackoverflow.com Dec 13 '10 at 15:38

This question came from our site for professional and enthusiast programmers.

2  
This isn't an easy question to answer, and you'll probably be better off asking at unix.stackexchange.com. –  Falmarri Dec 13 '10 at 2:08
    

3 Answers 3

If he was using screen, than you can do screen -r to attach the session to your session or screen -x to share the screen session.

Otherwise it will be slightly more difficult. You will probably have to change the rights of /dev/pts/3 first and after that you can do tail -F /dev/pts/3.

There is also another option, you can use ttysnoop for this. http://www.linuxhelp.net/guides/ttysnoop/

share|improve this answer
    
WoLpH, thank you for your answer. The friend actually used a python script to ssh into my machine and run this script. Can I still use any of the above solutions of yours? –  Anonymous Dec 13 '10 at 2:27
    
Also, do you happen to know if the friend can modify his script to SSH into my machine and run the local script using 'screen'? will it then allow me to view the output? –  Anonymous Dec 13 '10 at 2:32
    
@user540009: the last 2 solutions should still work, even when being executed from a script. With screen you can just do something like this: screen -S some_name the_python_app –  Wolph Dec 13 '10 at 3:02
    
WoLpH, I tried to run 'screen -S some_name the_python_app' from within Python but I get a message: 'Must be connected to a terminal.' –  Anonymous Dec 13 '10 at 3:30

Using ssh -t will make the screen suggestion by WoLpH work.

ssh -t <remote_host> screen

gives me a screen on the remote_host.

share|improve this answer
    
Good point; I've never had to use it, screen has always been fine, but I see that it might sometimes be required. –  El Yobo Dec 13 '10 at 3:47
    
+1 from me :) Soon you'll have enough rep for comments ;) –  Wolph Dec 13 '10 at 10:50
    
And indeed I do, thanks! –  kasterma Dec 13 '10 at 13:44
    
Kasterma, putting aside the 'ssh' issue, is it possible to run this from a python script? I tried invoking: os.system("screen -S some_name python python_script.py") but it gives me an error: 'Must be connected to a terminal.' what am I missing? –  Anonymous Dec 13 '10 at 15:03
    
If there is to be no interaction between the two people and you just want to share the output, the answer to this question at the unix and linux stackexchange is the easier way to go: unix.stackexchange.com/questions/4786/view-script-over-ssh I have never tried to run screen from within python. –  kasterma Dec 13 '10 at 15:37

Assuming you are logged in with different user accounts. The short answer is, you can't. If you could that would be a security problem. Your regular user account won't have permissions to read the process, pty, and socket of the other process.

Screen might help, but must be compiled with multiuser support, and then installed and configured properly (with ACLs, etc). If that is done beforehand then you can use screen.

e.g. from client: ssh -t friend@host screen -r me/[session]

Another option is the ttysnoop, but again requires some pre-configuration.

The real question is "why do you want to do that?" What is the end-goal you are trying to achieve? There is probably another, better way.

share|improve this answer
    
Keith, thank you for your answer. What I am trying to achieve is the following: (1) [working with machine A] run a python script programatically on machine A { meaning, a script will be running a script using say os.system(....) } (2) [working with machine A] the script that we ran in (1) is printing information to the screen (of machine A). (3) [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) if it matters, I use the same username on both machines. –  Anonymous Dec 13 '10 at 15:06
    
Well then, it sounds like plain ol' screen will work for you then. Give it a try. –  Keith Dec 14 '10 at 5:00

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.