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.

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

I'm pretty sure such a thing is possible by simpler means than debugging (result of my Google searches).

Can anyone help?

share|improve this question
While I understand that sometimes the need arises to capture content on another tty after a command is running, an ounce of prevention is worth a pound of cure, so always consider starting using screen or tmux before starting a command that you may want to access from another terminal. –  depquid Apr 14 '13 at 20:33

3 Answers 3

up vote 4 down vote accepted

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

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.

share|improve this answer
Exactly what I've been looking for (I've used it in the past, but forgot the name and couldn't remeber). Many thanks, I temporarily used dirty option (gdb and output replication). –  AoeAoe Apr 13 '13 at 23:40
Yes, the gdb was the first option I came across, I've used it myself in the past, but it's hacky, to me at least. Glad this helped you out! –  slm Apr 13 '13 at 23:43
ttylog can't seem to attach to the correct process though - can anyone answer my question: serverfault.com/questions/560972/… –  LittleBobbyTables Dec 12 '13 at 17:05

Indeed it is. The /dev/vcs* and /dev/vcsa* devices corresponds to the /dev/tty* devices (the virtual terminals). F1=tty1=vcs1/vcsa1 and so on. The vcs/vcsa is like tty for the "current" virtual terminal.

As root, you can just cat these devices (e.g. cat /dev/vcs2), and see what's on the corresponding VT (e.g. /dev/tty2 the on on F2) like taking a snapshot. vcsa* differs from vcs* in that they include information about the dimensions of the terminal (the screen). Mind you, it's just a raw snapshot of the characters as they show on the screen - gathered from the memory allocated to the terminal - so don't expect nice, easily parseble output.

The drawback is that if the information flashes past too fast, it may be difficult to capture. Perhaps tail -f /dev/vcs1 will work, if you need to follow several screenfulls (haven't tried myself)? It may be easiest to simply redirect it to a file first. It may also be a good idea to use a VT (F1-F6) to look at it, as the terminals will have the same dimensions. In my experience, it's best to use the vcs* - not the vcsa* - devices.

If that doesn't work, perhaps one of the "big brotherish" packages that allows an admin to keep an eye on the activity on a terminal may work.

PS: I forgot to ask what OS you use. This is for Linux, though similar devices probably exists on other OSes too. Try searching for "virtual console memory" among the man-pages for devices.

share|improve this answer

Another approach is to use the gnu screen utility on your local machine. Invoke it with the -L option, or start without that option and use the ^aH command sequence. Either approach causes all input & output to be logged to a file named screenlog.x where x is the screen number.

This is a handy because nothing extra needs to be installed on the remote machine.

share|improve this answer

Your Answer


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.