Screen terminal multiplexer: Difference between revisions

From Alpine Linux
(Use 'screen' on Alpine)
 
(Reorganizing the page)
Line 1: Line 1:
This document is a short note on how to monitor what's happening on the console.
= About screen =
'screen' is a good tool for remote support.<BR>
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.<BR>
To know if you are inside a 'screen' session, use the notes in '[[#Get_help|get help]]' section mentioned below.


'''Install programs'''
= Install =
  apk_add screen
{{cmd|apk add screen}}


= Use screen =
== Start a new session ==
{{cmd|screen}}


'''Make it autostart'''
== List existing sessions ==
 
{{cmd|screen -list}}
Lets 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
 
 
'''Not only the console...'''
 
The above example holds the if-statement:
  && [ -z "$SSH_TTY" ]
This statement sees to that no ssh-sessions is forced into a screen.<BR>
In case you want ssh-sessions to be forced into a screen, this option can be omitted.
 
 
'''Check for available sessions'''
 
To check what available screen-sessions are available:
  screen -list
You might get a list that looks like this:
You might get a list that looks like this:
  There are screens on:
<pre>
          11151.pts-1.mhlab01    (Attached)
There are screens on:
          11131.pts-3.mhlab01    (Attached)
        11151.pts-1.mhlab01    (Attached)
  2 Sockets in /var/run/screen/S-root.
        11131.pts-3.mhlab01    (Attached)
2 Sockets in /var/run/screen/S-root.
</pre>


== Attach to a existing session ==
Lets say you want to attach to a existing session (e.g. the above "11131.pts-3.mhlab01" session).
{{cmd|screen -x 11131}}
or
{{cmd|screen -x pts-3}}


'''Attach to a session'''
== Close or kill a session ==
When you are inside a 'screen' session you can 'kill' it by using:
{{cmd|CTRL+A k}}
or you might just type:
{{cmd|exit}}


Lets say you want to attach to a existing session (e.g. the above "11131.pts-3.mhlab01" session).
== Get help ==
  screen -x pts-3
'screen' has various options/commands.<BR>
When your inside a 'screen' session you can get help and see what options you have by using:
{{cmd|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.<BR>
Note that the this configuration will not force SSH-users into a screen.<BR>
Edit `/etc/profile` and add the following code to it:
<pre>
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
</pre>


'''Help'''
== Force console and SSH users into a screen session ==
 
The above example holds the if-statement:
'screen' has various options/commands.<BR>
&& [ -z "$SSH_TTY" ]
When your inside a 'screen'-session you can:
Remove this part from above configuration to force SSH sessions into a screen session.<BR>
  CTRL+a ?
{{Note|Console users will also be forced into a screen session when folowing these instructions}}
(Don't hold CTRL when entering ''''?'''')

Revision as of 03:23, 7 January 2011

About screen

'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