Linux "Screen" utility can be very useful for troubleshooting

  • KM03806284
  • 19-Apr-2021
  • 19-Apr-2021

Summary

Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). The screen utility is an excellent troubleshooting tool when you have a single connection and need multiple shells and also if you'd like to have processes running while you are no longer logged in.

Question

Practical uses in ITOM:
Screen can be used in our ITOM or any Linux environment when you are performing multiple tasks 
at the same time from one session or terminal.  Screen is valuable when you want to run functions 
when you are no longer logged into the system.  You can opt out (detach) of your shell while you are still 
running commands and even logoff while your screen shell runs within screen.  To get back into your 
detached screen shell you simply reattach to that shell.  From one terminal you can have numerous shells
and come in and out of them with ease while they run within the screen session.
 
*screen shells do not survive a reboot
 
How to manipulate screen windows in Linux from a single terminal session:
 
The following commands allow you to manipulate your way through multiple screen windows or shells to allow you
to run programs unattended for different functions from one terminal connection or no connection if you log out and leave screen active.
Examples for creating, attaching, detaching, reattaching and removing screen shells from the linux command line.
 
List any screen shells in your environment.
# screen -list
 
The following commands can be ran on the command line and within a screen shell.
Create 2 shells and attached to each.
# screen -S dmm
# screen -S mmd
# screen -list
 
There are screens on:
        28157.dmm       (Attached)
        28176.mmd       (Attached)
 
Detach screen shell dmm and keep the shell active.
# screen -d 28157.dmm
# screen -list
 
There are screens on:  (both screens active and you are attached to one and detached from the other)
        28157.dmm       (Detached)              <-no longer in the shell but the screen shell is still active
        28176.mmd       (Attached)
 
Reattach to the "28157.dmm" screen shell.
# screen -r 28157.dmm
# screen -list
There are screens on:                                        
        28157.dmm       (Attached)
        28176.mmd       (Attached)
 
Create a screen called ddd and make it detahced.
# screen -d -m -S ddd
# screen -list
 
There are screens on:
        28157.dmm       (Attached)
        28752.ddd       (Detached)                  <-newly created and you are not yet attached
        28176.mmd       (Attached)
 
Removing a screen shell from within the shell itself, in the example you are attached to 28752.ddd.
There are screens on:
        28157.dmm       (Attached)
        28752.ddd       (Attached)                    <-attached here
        28176.mmd       (Attached)
 
# exit
 
Now the screen window or shell 28752.ddd is no longer running.
# screen -list
 
There are screens on:
        28157.dmm       (Attached)
        28176.mmd       (Attached)
 
Don't forget to remove all your screen windows when you are finished.
 
There are many more command line options used by screen that can be found in the resources section below.  Screen also uses 
key bindings that have similar functions but only used within the shell windows.  These can also be found in the resource pointers below.
 
Resources:
Screen User's Manual
http://www.gnu.org/software/screen/manual/screen.html
and
Linux man pages: # man screen
 

Answer

There are many good reasons for using "screen" in linux to help troubleshoot issues.  The topic session gives pratical examples on manipulating windows or shells within screen.