server administration tutorial unix

Sharing and Logging Sessions with Screen

Screen is a program that can be used to manage multiple shells from within one connection. You can navigate between terminals as well as detach the screen so the programs you are running will continue to run in the background after the connection is broken. One overlooked feature is the ability to display and/or show what you are doing to another user in realtime.

Screen has many features, but the two I will concentrate on today are sharing of sessions and logging output, both of which are extremely useful. First though, I will give a brief introduction to Screen and it’s uses.

If you have not done so already, you will want to install screen either by compiling from source or through your package manager. I will not go into detail on how to install screen, as a quick Google search should explain all you need to know.

Once you have Screen up and running, you can create and move through windows. Please note, the keystrokes and commands covered here are just a minimal set of what Screen can do, if you want more functionality, please check the screen manpage.

After you have started a Screen session with the screen command, you have a few keystrokes that are critical to moving through and managing your windows. Please note, all keystrokes begin with ‘CTRL-a’, and then are followed by another character. For example, in order to create a window you would use ‘CTRL-a c’. The following table assumes you use control-a proceeding all of the commands so only the character is listed.

key Description
c Creates a window.
n Moves to the next window.
p Moves to the previous window.
d Detaches Screen.

Now that you have the basics of Screen, we can cover logging and sharing sessions. Sharing sessions is useful for example if you wish to help someone perform a task or let them monitor what you type into a shell as you are providing support. In order to share a session, one party needs to create the session by using screen -S foobar. Make sure that the session name is named so that you will remember it. In this example, the session name would be ‘foobar’. Then in order for the other party to connect, they just need to use screen -x foobar.

If you do not create a session, you can use screen -list to find the created screen. From there, you can specify the name.

Logging is yet another useful feature of screen; you can provide support or even keep track of your own actions by using screen -L. Screen will create a “screenlog.x” where x is the number of the window you are in to log each window.

As always, comments, ideas and suggestions for this article or future articles is welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.