Screen terminal multiplexer

From Alpine Linux
Revision as of 06:07, 8 December 2011 by Fab (talk | contribs)

'screen' is a good tool for remote support. It can also be used to start a command you want to keep running after you close your console session (you can later on attach to your running 'screen' session). When you enter a 'screen' session you will not notice too much.
To know if you are inside a 'screen' session, use the notes in 'get help' section mentioned below.

Install

apk add screen

Use screen

Start a new session

screen

List existing sessions

screen -list

You might get a list that looks like this:

There are screens on:
        11151.pts-1.mhlab01     (Attached)
        11131.pts-3.mhlab01     (Attached)
2 Sockets in /var/run/screen/S-root.

Attach to a existing session

Lets say you want to attach to a existing session (e.g. the above "11131.pts-3.mhlab01" session).

screen -x 11131

or

screen -x pts-3

Close or kill a session

When you are inside a 'screen' session you can 'kill' it by using:

CTRL+A k

or you might just type:

exit

Get help

'screen' has various options/commands.
When your inside a 'screen' session you can get help and see what options you have by using:

CTRL+a ?

(Do not press/hold 'CTRL' when entering '?')

Extra

Force console users into a screen session

In some cases you might want to force only console users into a screen session.
Note that the this configuration will not force SSH-users into a screen.
Edit `/etc/profile` and add the following code to it:

if [ -n "$PS1" ] && [ -z "$STARTED_SCREEN" ] && [ -z "$SSH_TTY" ]; then
  STARTED_SCREEN=1 ; export STARTED_SCREEN
  screen -RR && exit 0
  echo "Screen failed! continuing with normal bash startup"
fi

Force console and SSH users into a screen session

The above example holds the if-statement:

&& [ -z "$SSH_TTY" ]

Remove this part from above configuration to force SSH sessions into a screen session.

Note: Console users will also be forced into a screen session when folowing these instructions