# Eavesdropping on another terminal...

## npmccallum

I am currently running a very very long process on a box in another room (it is running on the first virtual terminal).  I would like to log in (as root of course), via ssh (which is setup), and view what is going on on the screen of virtual terminal 1 (to monitor the progress).  How do I do this?

----------

## jimlynch11

i was wondering about the same thing today...i think there is a way you can send all of the output to a log file, then monitor that...im not sure how to set it up or if it is the best option

----------

## blscreen

If you know that you want to monitor the process before starting it, 'screen' would fit your needs. You can start whatever you like in screen and then detach and resume remotely. This does not help you if you cannot interrupt the running process though   :Confused: 

----------

## npmccallum

 *blscreen wrote:*   

> If you know that you want to monitor the process before starting it, 'screen' would fit your needs. You can start whatever you like in screen and then detach and resume remotely. This does not help you if you cannot interrupt the running process though  

 

What does 'screen' do?

----------

## Reverend

 *blscreen wrote:*   

> If you know that you want to monitor the process before starting it, 'screen' would fit your needs. You can start whatever you like in screen and then detach and resume remotely. This does not help you if you cannot interrupt the running process though  

 

You know, I can never seem to figure out how to use this program. The man page tells you everything that you might want to do, but doesn't just break it down to the most common sequence of commands.

Say for example, I'm at work and start up a 'emerge -u kde' and I know it's going to be running for a while over the weekend. So, I want to run it inside screen so that I can check on it from home over the weekend. What do I do?

Do I run screen, then execute the emerge command from within? Then what do I do at home?

Could you, or someone, please just give an example set of commands and keystrokes sent to screen to be able to periodically check in on a long running process?

Thanks!

----------

## MacFlecknoe

look in this months Linux Magazine... they have a nice writeup on the 'screen' program; you can pick a copy up at Barnes & Nobles

----------

## aardvark

 *Reverend wrote:*   

>  *blscreen wrote:*   If you know that you want to monitor the process before starting it, 'screen' would fit your needs. You can start whatever you like in screen and then detach and resume remotely. This does not help you if you cannot interrupt the running process though   
> 
> You know, I can never seem to figure out how to use this program. The man page tells you everything that you might want to do, but doesn't just break it down to the most common sequence of commands.
> 
> Say for example, I'm at work and start up a 'emerge -u kde' and I know it's going to be running for a while over the weekend. So, I want to run it inside screen so that I can check on it from home over the weekend. What do I do?
> ...

 

screen is easy

just emerge it

the type screen 

do your stuff...

then hit ctrl+a d 

now connect to that screen again (even fom an ssh session) with 

```
 screen -r

```

It is alsi possible to connect to a screen that is attached

I believe it is screen -x....

check the manpage

----------

## npmccallum

There is no way to do this without screen?  Shouldn't root be able to see other people's sessions? or is this disabled for security reasons?

----------

## aardvark

 *npmccallum wrote:*   

> There is no way to do this without screen?  Shouldn't root be able to see other people's sessions? or is this disabled for security reasons?

 

screen is a small program. I don't see why you would do it an other way.

I once looked for a solution for the issue you mention (for 2 whole hours... :Sad:  ), and the only practical "hassle free" solution I found was .... screen... . When I know I'm not going to be on he same terminal for a certain operation I always just start the process in a sceen...

Even my server adsl script on the server runs in a screen so that I can check it out when the connection seems down  :Smile: 

----------

## npmccallum

 *aardvark wrote:*   

> 
> 
> screen is a small program. I don't see why you would do it an other way.
> 
> I once looked for a solution for the issue you mention (for 2 whole hours... ), and the only practical "hassle free" solution I found was .... screen... . When I know I'm not going to be on he same terminal for a certain operation I always just start the process in a sceen...
> ...

 

'screen' doesn't help when you are doing a system install  :Sad: 

----------

## blscreen

 *Quote:*   

> Could you, or someone, please just give an example set of commands and keystrokes sent to screen to be able to periodically check in on a long running process? 

 

Start with

```
screen
```

This drops you into your shell, you don't notice any differences. Then start whatever is going to run a long time.

You can create more virtual terminals in the current screen session:

```
Ctrl-a c
```

  It is possible to switch between the terminals with 

```
Ctrl-a 0..9
```

 (direct access) or with 

```
Ctrl-a n
```

 (go to the next terminal).

As mentioned before 

```
Ctrl-a d
```

 detaches the current screen session with all of its virtual terminals. To resume, just type 

```
screen -r
```

 or 

```
screen -d -r
```

 if the session has not yet been detached (connection broke or something).

This are the commands I use most (mainly to chat over an irssi running at home when I am at my working place, so I don't need to install a client on this windows box)  :Wink: 

----------

## blscreen

 *Quote:*   

> 'screen' doesn't help when you are doing a system install

 

Well, you have to install some software before you can do the monitoring. If you have installed sshd, why not as well screen, or am I getting something wrong here  :Rolling Eyes: ?

Another possibility is 'ttysnoop', which is a client-server based solution. The server 'ttysnoops' is started by agetty instead of /bin/login (ttysnoops now takes care about that). With the client 'ttysnoop' you can then watch what is going on in this terminal. This is more of a spyware than 'screen' because the users might not know that their actions are under observation.

----------

## npmccallum

 *blscreen wrote:*   

>  *Quote:*   'screen' doesn't help when you are doing a system install 
> 
> Well, you have to install some software before you can do the monitoring. If you have installed sshd, why not as well screen, or am I getting something wrong here ?
> 
> Another possibility is 'ttysnoop', which is a client-server based solution. The server 'ttysnoops' is started by agetty instead of /bin/login (ttysnoops now takes care about that). With the client 'ttysnoop' you can then watch what is going on in this terminal. This is more of a spyware than 'screen' because the users might not know that their actions are under observation.

 

If its not on the gentoo live cd (sshd is on the cd), I can't monitor the installs going on in the other room  :Smile: 

----------

## dma

It can be done through /dev/vcsa*

It dumps the contents of a VC to the current terminal (including colors).

You can type "man vcsa" for more info.

I'll make you a prog to dump it to your console (THIS IS HORRIBLY INEFFICIENT!):

```
#!/usr/bin/perl

%COLORMAP = (

    0 => 0,    1 => 4,    2 => 2,    3 => 6,

    4 => 1,    5 => 5,    6 => 3,    7 => 7 );

if ($#ARGV != 0) {

    die "$0: must give a vcsa device.\n";

}

$F = $ARGV[0];

open(VCSA, "<$F") or die "$0: unable to open $F ($!)\n";

my $Columns = ord(getc(VCSA));

my $Lines = ord(getc(VCSA));

my $CurX = ord(getc(VCSA));

my $CurY = ord(getc(VCSA));

my $LINE = 0;

my $COL = 0;

my $ATTR;

my $CHAR;

# Main stuff.

for ($COL = 0; $COL < $Columns; $COL++) {

    for ($LINE = 0; $LINE < $Lines; $LINE++) {

        $CHAR = getc(VCSA);

        $ATTR = ord(getc(VCSA));

        print "\e[0;";

        my $bg_col = $COLORMAP{ ($ATTR & 0x70) >> 4 };

        print "4", $bg_col, ";";

        my $fg_col = $COLORMAP{ ($ATTR & 0x07) };

        if ( ($ATTR & 0x0F) >= 0x08 ) {

            print "1;";

        }

        print "3", $fg_col, "m";

        print $CHAR;

    }

    print "\n";

}

close(VCSA);

```

----------

## jkcunningham

If you are really opposed to screen, there is another way: ssh into the remote machine and launch it via the ssh window. Then its right there for you to watch. Of course, if you move to the remote terminal, so that its local, you won't be able to see it anymore. Just a thought. 

-Jeff

----------

## npmccallum

 *jkcunningham wrote:*   

> If you are really opposed to screen, there is another way: ssh into the remote machine and launch it via the ssh window. Then its right there for you to watch. Of course, if you move to the remote terminal, so that its local, you won't be able to see it anymore. Just a thought. 
> 
> -Jeff

 

Thats what I've been doing.  But somtimes I have to shut down the computer I'm observing from and I don't want to interrupt the install.  Oh well.

(I'm not OPPOSED to screen, it just isn't on the Gentoo Live CD. Or is it!?)

----------

## dma

The program I wrote a few posts back will dump the current contents of a console (/dev/vcsa1 for #1) to your machine over ssh or whatever.  It isn't optimized and it requires perl...  But I only spent a few minutes writing it.

It is like taking a remote screen shot.  Requires no previous work on the console in question.

----------

## jimlynch11

 *blscreen wrote:*   

>  *Quote:*   Could you, or someone, please just give an example set of commands and keystrokes sent to screen to be able to periodically check in on a long running process?  
> 
> Start with
> 
> ```
> ...

 

blscreen: you are my hero. the program screen is the best thing ever!

----------

## bos_mindwarp

For viewing the ouput of the process:

1.) logon (via ssh or similar)

2.) type:

```
nohup emerge kde &
```

3.) logoff

4.) do something else

5.) logon

6.) type:

```
tail -f nohup.out
```

7.) CTRL-C

8.) logoff

9.) repeat steps 5-8 as much as you want.

----------

## chris84ae

if you just wont to view the output remotely and remain in control locally you can use tee

e.g.

emerge kde|tee output.log

you remian in control on the local screen

and you can tail output.log on a remote terminal

----------

## viperlin

sometimes i let my friends ssh into my computer to either show them my latest script (my latest at this point being a script that perfectly imitates the trinity hack from the matrix reloaded, will be GPL and on my website soon)

last time after they looked @ my script. they ran "links" and started downloading pr0n pics to their account folder.

i need a way to simply snoop in on what they are doing (i own the host so i'm looking for a server side prog)

so i can maybe run "programname $username", e.g "sshwatcher chris" and it will show me what he's doing as if i was looking over his shoulder.

any idea's, i can't find anything in the portage tree.

----------

## Lightspeed

 *jkcunningham wrote:*   

> If you are really opposed to screen, there is another way: ssh into the remote machine and launch it via the ssh window. Then its right there for you to watch. Of course, if you move to the remote terminal, so that its local, you won't be able to see it anymore. Just a thought. 
> 
> -Jeff

 

You could always run the above mentioned ssh connection inside screen. Then if you want to go back to the machine the app is actually running on (or any other computer, for that matter) and still access the app you can setup another ssh connection to the previous computer and attach to the screen session. This will then work for installs from a live cd which has ssh but not screen installed.

----------

