Screen

Monday, May 07, 2007
Posted by Barts

I work a lot on remote Linux servers, deploying and testing my code. One of the most useful tools I use all the time is screen. Basically, it allows user to have multiple sessions in one console window and it supports resuming these sessions when connection is interrupted. Where it not for screen, I would waste hours of my life setting up things after getting disconnected. Also, if you don't have Midnight Commander, the ability to have more than one session is also very handy. You can read more about screen here and about handy shortcuts here.

Screen screenshot

One little disadvantage of screen is that if the server is reset, then the user loses all their session information. Nevertheless, there is a trick to speed up a lot setting up new screen session and it's not something very well documented, so I describe it here.

Basically user needs to edit (or create, if it is not there) the file .screenrc in their home directory so that it contains the commands to be executed in its respective screens (aka sessions). Below you can see my example :
info xterm ti@:te@
shell bash
chdir /somewhere/src/
screen -t XXX_source 0
shell bash
chdir /somewhere/some_server/
screen -t XXX_server_1 1
shell bash
chdir /somewhere/some_other_server/
screen -t XXX_server_2 2
shell bash
chdir /somewhere/vobs/
screen -t XXX_vob 3

What it does is basically create four screens in one screen session - think of them as four tabbed browsing windows. Each of them will be using bash shell (just because I like it) and start in appropriate directory (source dir, where I make my builds, two server paths and one vob directory for version control related stuff). Each XXX_something part is the name of the respective session window (displayed on top of Putty terminal, for example). Simple, neat, and very helpful. Also, the structure of the file is pretty much self-explanatory.

I know it is not a very complicated thing, but it saves a lot of time and therefore I thought I'd bring it to your attention. As always, I look forward to your comments.

0 comments: