Terminal TTY – How to Hook on to One Terminal’s Output from Another Terminal

terminalterminal-emulatortty

I need to hook onto output of currently running terminal (tty1) from virtual terminal and capture it (running X server).

Best Answer

I came across this one tool called ttylog. It's a Perl program available on CPAN here. It has a couple caveats, one being that I could only figure out how to attach to a terminal that was created as part of someone ssh'ing into my box. The other being that you have to run it with elevated privileges (i.e. root or sudo).

But it works!

For example

First ssh into your box in TERM#1:

TERM#1% ssh saml@grinchy

Note this new terminal's tty:

TERM#1% tty
/dev/pts/3

Now in another terminal (TERM#2) run this command:

TERM#2% ttylog pts/3
DEBUG: Scanning for psuedo terminal pts/3
DEBUG: Psuedo terminal [pts/3] found.
DEBUG: Found parent sshd pid [13789] for user [saml]

Now go back to TERM#1 and type stuff, it'll show up in TERM#2.

ss of terminals

All the commands I tried, (top, ls, etc.) worked without incident using ttylog.

Related Question