Installing and Using GNU ScreenBy Amy Rich Much of today's system administration is done remotely by means of either a console server or a direct ssh connection to the machines themselves. Since these connections run over TCP, an unreliable IP network can cut the sysadmin's connection to a host during the middle of a critical task. Once that interactive session is disconnected, there's no way to return to the running processes, even if the shell continues to run on the remote machine. Screen, GNU's terminal-based windowing system, allows the sysadmin to reconnect to a running shell on a remote system so that poor network connectivity won't result in the loss of the session. Screen is a full text-based windowing system designed to allow the
multiplexing of several sessions in one physical window. All virtual windows
are children of the initial screen process but run their programs completely
independent of each other. Screen is generally run from an xterm or a
directly attached serial terminal. A prefix key ( When starting a new session, screen first reads, in order,
Once screen is run, any processes started from within the screen session stay active until explicitly ended or the screen session itself is ended or corrupted. If the user detaches from the screen session, a process listing will show the running processes, but the user is removed from wtmp and utmp so that utilities such as finger, who, and last do not show the user. When the user reconnects to the session, the utmp and wtmp information is modified and finger, who, and last once again list the user as logged in. Building and Installing ScreenScreen is available from the Solaris Companion Software CD, ftp.uni-erlangen.de and various GNU mirror sites. To install it, download the source, unpack it, configure it, and compile it: ncftpget ftp://ftp.uni-erlangen.de/pub/utilities/screen/screen-4.0.1.tar.gz gtar zxf screen-4.0.1.tar.gz cd screen-4.0.1 ./configure make make install This installs screen, but does not modify the termcap and terminfo
databases or install the default screenrc file. To do so, copy
screen-4.0.1-pkginfo BASEDIR=/usr/local PATH=/sbin:/usr/sbin:/usr/bin:/usr/sadm/install/bin PKG=GNUscreen NAME=screen VERSION=4.0.1 ARCH=sun4u CATEGORY=application VENDOR=GNU EMAIL=gnu@gnu.org PSTAMP=20031015 CLASSES=none screen-4.0.1-postinstall #!/bin/sh TERMCAPINFO=`/usr/bin/grep screen-w /etc/termcap` if [ -r /etc/termcap ] && [ -f $BASEDIR/etc/screencap ] && [ "X$TERMCAPINFO" = X]; then /bin/cp /etc/termcap /etc/termcap.orig /bin/cat $BASEDIR/etc/screencap >> /etc/termcap fi if [ -d /usr/share/lib/terminfo ]; then /usr/bin/tic $BASEDIR/etc/screeninfo.src /usr/bin/chmod 644 /usr/share/lib/terminfo/s/screen* fi /bin/rm -f $BASEDIR/etc/screencap /bin/rm -f $BASEDIR/etc/screeninfo.src screen-4.0.1-prototype i pkginfo=screen-4.0.1-pkginfo i postinstall=screen-4.0.1-postinstall !search /usr/local d none bin 0755 root other f none bin/screen-4.0.1 4755 root other s none bin/screen=screen-4.0.1 d none etc 0755 root other f none etc/screenrc 0644 root other f none etc/screencap 0644 root other f none etc/screeninfo.src 0644 root other d none man 0755 root other d none man/man1 0755 root other f none man/man1/screen.1 0644 root other d none info 0755 root other f none info/screen.info 0644 root other f none info/screen.info-1 0644 root other f none info/screen.info-2 0644 root other f none info/screen.info-3 0644 root other f none info/screen.info-4 0644 root other f none info/screen.info-5 0644 root other f none info/dir 0644 root other Run
/usr/bin/pkgmk -b /usr/local -o -f screen-4.0.1-prototype cd /var/spool/pkg; /usr/bin/pkgtrans -s `pwd` /tmp/GNUscreen-4.0.1-sparc.pkg rm -rf /var/spool/pkg/GNUscreen /usr/bin/pkgadd -d /tmp/GNUscreen-4.0.1-sparc.pkg Common Screen TasksStarting and Selecting WindowsOnce screen is installed, it can be used without any further configuration.
First run In addition to shell windows, screen can also attach directly to serial
devices. This is quite useful when installed on a machine acting as a console
server to a number of other machines or on a machine directly attached to a
modem. To attach directly to /dev/ttyb, for example, enter command mode and
give the screen command port as an argument: Once a screen session has multiple virtual windows, the user needs to
easily switch between them. Like a TV remote, screen can access windows by
using a wraparound To switch to the next window in sequence, enter the key sequence History, Cut and Paste, Logging, and MonitoringWhen the user is working on a terminal that has no mouse, screen offers the capability
to cut and paste by using a virtual clipboard. The key sequence Activity in a screen virtual window can be logged to a file, much like the
UNIX Locking and Detaching, and ReattachingPerhaps the two most useful features of screen are the ability to lock the
terminal and the ability to disconnect the session and later reconnect. To
lock the terminal (or xterm, if called from one), enter the key sequence
There are two ways to detach a screen session, power detach and a regular
detach. In a regular detach ( Screen sessions can also be detached from outside the screen session,
which is useful for stealing a session after changing physical locations. Again,
sessions can be detached regularly or power detached, but if a user runs more
than one screen session, the correct session to detach must first be
determined. This is done by issuing
% screen -ls
There are screens on:
651.pts-5.hostname (Attached)
16405.pts-12.hostname (Attached)
2 Sockets in /tmp/screens/S-username.
To detach the session screen -d 651.pts-5.hostname screen -D 651.pts-5.hostname If there was only one active session, screen could be called without the session name: screen -d screen -D There are a variety of ways to reattach to a detached session, some of
which will even detach the session first if needed. Each of the following is
a command-line option to the
When a screen session dies, either because the machine rebooted or the
process got killed or corrupted, the dead socket file can be left in the
screen directory. A dead screen session cannot be reattached, and the sockets
should be cleaned up. These dead screens are visible with the Customizing ScreenScreen can be effectively run without any configuration at all, but most sysadmins will want to change some default behaviors and create shortcuts with key bindings. Most customization occurs via the screen resource files, though sessions can also be customized from the invoking command line or on the fly. Directives in the resource files set options, bind functions to keys, and automatically start virtual windows at the beginning of the session. Each directive is listed one per line with the arguments separated by tabs or spaces. The pound sign (#) acts as the comment delimiter, and any text appearing on a line after one is ignored. Any blank lines in the file are ignored. The arguments section of each directive can contain references to environment variables as well as plain text. Here's a short example $HOME/.screenrc file containing comments for each directive:
# set some options
activity "activity: window ~%" # Message when activity occurs in a window
vbell_msg "bell: window ~%" # Message for visual bell
vbellwait 2 # Seconds to pause the screen for visual bell
allpartial off # Refresh entire screen on window change
autodetach on # Autodetach session on hangup instead of
# terminating screen completely
bufferfile /tmp/screen-buffer # Filename for the paste buffer
chdir # Change to the home directory
escape "``" # Redefine the prefix key to ` and define a
# literal ` as ``
shelltitle $HOST # Set the title of all shell windows
defflow off # Set the default flow control mode
defmode 0620 # Set the default mode of each pseudo tty
defscrollback 200 # Set the default number of scrollback lines
deflogin off # Do not register the window in utmp
startup_message off # Disable startup messages
# virtual windows to start when screen starts
screen -t emacs@$HOST -h 0 1 /usr/local/bin/emacs -nw
# Start emacs in window 1 with a scrollback
# buffer of 0
screen -t tcsh@$HOST -ln -h 100 2
# Start a shell with the title of
# tcsh@
As shown above, one very common modification is changing the prefix key
from ResourcesThe
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
|