"The Linux Gazette...making Linux just a little more fun!"

(?) The Answer Guy (!)

By James T. Dennis, tag@lists.linuxgazette.net
LinuxCare, http://www.linuxcare.com/

(?) Flexible Logging of Terminal Output to Files: Use 'screen'

From Phillip Nguyen on Thu, 01 Apr 1999

(?) Hi,

The Linux xterm does not give me the option to log the screen to file in the pop up windows (Ctrl-leftbutton).

I know I can use script to log the screen, but that means I have to get out of telnet run the script program then run telnet again. My problem is I don't want to log the whole session, I only wants part of the session here and there to do debugging. Is there a way that I can make Linux xterm to give me the "Log to file" option in the pop-up window.

Thanks. Phillip.

(!) Use 'screen' --- you'd start that before you start your 'telnet' session (assuming that you want to log to a file on your local system).
'screen' has a number of nice features for users of consoles, telnet, dial-up terminals, and xterms. When you start it, 'screen' reserves one key ([Ctrl]+[A] by default) as a way to access it's many options. Of course you can set that meta key to some other value. I'll refer to it in the following text as [Meta]
You use [Meta],[H] (upper case) to start logging. This will create a file, in the directory from which you started 'screen' named screenlog.0 (the first time you start one). You can toggle this on and off (and it will close and reopen the file as appropriate). Actually the "Hardcopy" file will be named screenlog.N where N is the number of the window from which you started the logging. 'screen' allows you to start multiple interactive "windows" or "screens" through the same terminal connection (xterm, on the same virtual console, whatever). You can do this using [Meta],[c] to "create" additional screen sessions.
You can switch among screens (using [Meta],[Meta] to switch to the most recently used screen, [Meta],[Space] to cycle to the "next" screen, and [Meta] followed by a digit, to switch directly to one of the screens). You can "grab" a screen shot using [Meta],[h] (lowercase "H").
You can detach 'screen' from your terminal (all jobs started through it will continue running as though they were still connected to your terminal). You can then re-attach to any terminal you like. So you can detach from your xterm, logout, dial or telnet in from some other place, and re-attach to your 'screen' session where you can continue working right where you left off. (I'm running xemacs under 'screen' right now). 'screen' can also be configured to "autodetach" --- which is handy if you are logged in through a flaky modem or network connection. You just log back in and re-attach with the command 'screen -r'
You can also cut and paste using 'screen' keyboard bindings. So you use [Meta] "[" (left bracket) or [Meta],[Esc] (escape), to get into "cut/backscroll" mode. Then you use cursor movements (mostly like 'vi' bindings by default) to move your cursor to a starting location (on the screen or somewhere in 'screen's backscroll buffer). The you hit the space bar to start marking --- move you cursor to some later location and hit the space bar again to "cut/copy" the intervening text. You can then use [Meta]"]" (right bracket) to "paste" that text (which will act exactly as though you'd retyped it). This cut and paste feature can be very handy when you can manage to log into a system where you don't have any file transfer capabilities. You can at least cut and paste bits of configuration text to get things working on the remote system. It's also handy when you have something in one text mode app that you want to put in an editor. (I use it all the time to copy link information from Lynx, my web browser, into xemacs (my mail reader is an emacs mode, mh-e).
So, 'screen' is the power tool you need for this job.

Copyright © 1999, James T. Dennis
Published in The Linux Gazette Issue 41 May 1999

[ Answer Guy Index ] 1 2 3 4 5 6

[ Table Of Contents ] [ Front Page ] [ Previous Section ] [ Next Section ]