Saturday 5 August 2006 — This is more than 18 years old. Be careful.
At work, my ssh session to our servers time out quite frequently. It used to bother me a lot because it meant having to login to the machines many times a day, and losing the on-screen history of what I had been doing.
Not anymore. A co-worker introduced me to screen, a terminal multiplexor. In a nutshell, it manages virtual terminals that persist even when you log out. So if a connection to a server is dropped, logging in again will re-connect you to the session you had been working in.
Screen manages many virtual terminals, so one OS window can contain many Linux sessions within it, reducing desktop clutter.
Screen is quite complex, in the emacs mold: it can do many things, and has many commands, some of which are bound to keystrokes, but many of which are not. There are esoteric escape sequences that can be used to hyper-customize the environment, and more options than I can possibly understand. If you find yourself using many console windows on Unix boxes, do yourself a favor and learn enough about screen to get it working for you.
The documentation out there tends to be a bit overwhelming as well, falling into two camps: the exhaustive reference manual that begins with the command-line switches, or the informal tutorial that starts out talking about stuff you don’t understand. Here’s a shorter getting-started guide that might be helpful.
I’m tempted to write a mini-tutorial myself, but I don’t think I could really improve on what’s out there. I will give you my .screenrc file:
# Ned's .screenrc
escape ^L^L
vbell off
defscrollback 8000
hardstatus alwayslastline
hardstatus string '%{= KW}%-w%{= gW}%50> %n %t %{= KW}%+w%< %{= kG}%-=%{-}'
What does this do?
- Sets the escape character to ^L, because I don’t need that for any real use, and the default ^A is too handy for command-line editing.
- Turns off the visible bell, which is too much flashing for me.
- Sets a scrollback buffer of 8000 lines, because I like to look back through my console window for old stuff. One thing about screen: it manages the console window such that your real console window never scrolls, so you have to change where you store your off-screen lines. Your true console window doesn’t need them anymore; “defscrollback 8000” configures screen to keep them for you.
- Sets the hard status line to be the last line in the window, and to give it a simple tabbed look. This makes the last line in the window a list of your current screen sessions, in a nice green-on-gray theme.
Screen is a god-send.
Comments
My laptop's network connection would close, but the screen session on the Linux box would keep compiling.
One "problem" with screen -- whereas before it was annoying when I lost the past few hour's worth of session history, now on those occasions when machines have to be rebooted, I lose _weeks_ worth of session history, and that's _really_ painful.
I use backquote (`) instead of a control character, incidentally.
--titus
I also find xterm's (well, gnome-terminal's actually) scrollback easier to use (mouse wheel), so I the followng line to .screenrc to have both:
termcapinfo xterm|xterms|xs ti=\E7\E[?47l
-it's damn hard to find about: unless you have a co-worker that introduces you to that tool, there is little chance that you'll stumble on it
-for some reason, it's rather hard to explain. You did a pretty good job though. Here's my own attempt as well: Essential utility: "screen"
http://taint.org/wk/RemoteLoginAutoScreen
ServerAliveInterval 300
ServerAliveCountMax 3
That'll keep you logged in all day. :)
screen /dev/ttyS0 9600
I never ran minicom again.
Something I do use, however, is NX. When I'm working on a server, I can have up to 10 shells open simultaneously and it's pretty annoying to have to reconnect them all when I move my laptop between work to home. Now I just start an NX session and run konsole (great for multiple shells if you know the keystrokes) and maybe a web browser. Before I move to another location I suspend the session so that when I reconnect, everything is where I left it. If I want to work on a server without a graphical environment, I use a NX connection to one that does, and ssh from there.
As for the Putty disconnection problem, I've heard the complaint from many Windows users. Supposedly, there's some timeout value in the registry that you can increase, but I haven't used Windows seriously in over 10 years so I would have no idea how to find it.
Add a comment: