Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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


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

2 Answers 2

up vote 9 down vote accepted

You generally can't see the output of anther person's program. See over in that column where your grep command is running on tty pts/3, and your friend's is ?, which means it's detached from the terminal.

You could see where the output is going with ls -l /proc/7494/fd/ (where 7494 is the process ID of your friend's process) — although if you're not running as root, you probably can't even look, for security reasons. (So try sudo ls -l /proc/7494/fd/.)

There are horrible, horrible, kludgy things you might be able to do to change where the output of the program goes. But in general, you can't and shouldn't.

If your friend wants to share the output with you, and approach would be to redirect the output of the program to a file, and then make that file readable by you:

$ python -u TEST_AREA/justprint.py > /tmp/justprint.out &
$ chmod a+r /tmp/justprint.out

(Where in this case "readable by you" is "readable by everyone"; with a little more work you can set up a shared group so just the two of you can exchange output.)

(And be aware that python buffers output by default — turning that off is what the -u is for.)

share|improve this answer
    
Thank you for the detailed reply. –  user3077 Dec 13 '10 at 15:44

If you have root access on the machine and your friend is willing to execute some commands, it is possible:

  1. [Root] screen has to be setuid root: chmod u+s /usr/bin/screen
  2. [Friend] starts screen, he can give the session a name, makes it easier: screen -S "shared_session"
  3. [Friend] enables multiuser mode: Ctrl-a :multiuser on
  4. [Friend] enables you to access his screen session: Ctrl-a :acladd you
  5. [Friend] (Optional) restrictes your access to read-only: Ctrl-a :aclchg you -w "#"
  6. [You] attach onto friends screen: screen -x friend/shared_session

The setuid root is maybe a bit dangerous...

share|improve this answer
    
does it have to be suid? –  xenoterracide Dec 13 '10 at 9:58
    
if not, screen will exit with: Must run suid root for multiuser support. –  wag Dec 13 '10 at 10:05
1  
Using screen was also suggested at the crosspost of this question to stackoverflow: stackoverflow.com/questions/4425308/view-script-over-ssh/… Note that screen -t will work fine with no setuid root set. –  kasterma Dec 13 '10 at 13:50
    
thank you for the detailed reply. –  user3077 Dec 13 '10 at 15:44
    
@kasterma: I'm a bit skeptic if user A can actually attach to user B's screen without suid/root rights, can you explain that further? –  wag Dec 13 '10 at 18:03

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.