Screen Function for Linux and Unix-like
In the sysadmin world, the process of working on a system deployment project often requires quite a long time while we need a tool that functions to keep our terminal ‘on idle’ or no need to close the terminal, which can make it easier for a sysadmin to do their work when deploying, so the most appropriate solution is to use the ‘screen’ tool. This is a tool that can be said to be a veteran among unix or unix-like users or especially users of every linux variant who are certainly familiar with this tool.
Let’s get straight to how this tool works. Here are the flags commonly used by sysadmins, for more complete command documentation you can use the ‘man screen’ command
-ls [match]
-list [match] does not start screen, but prints a list of pid.tty.host strings and creation timestamps identifying your screen sessions.
-r [pid.tty.host]
-r sessionowner/[pid.tty.host] resumes a detached screen session.
-d|-D [pid.tty.host] does not start screen, but detaches the elsewhere running screen session. It has the same effect as typing “C-a d” from screen’s controlling terminal.
1. Starting a session
run the command ‘screen’ in the terminal, displayScreen Display
2. Detaching a session (background session)
run the command “Ctrl+a+d” when the session is openDetach Screen
3. View session list
Run the command ‘screen -ls’ or ‘screen -list’Listing Screen
4. Resume session
Run the command “screen -r [pid.tty.host]”Resume Screen
*pid : process id, tty.host : terminal session
5. Detach session without logging into session
Run the command “screen -d [pid.tty.host]”Detach Screen
*pid : process id, tty.host : terminal session
## Bonus
we can also create a new session but this new session is a connection to another ssh server.
screen -d -m -S svr1 -t rocky@svr1
ssh server1.abc.org
or we can also create a new session for multiple ssh sessions using a simple bash script.
#!/bin/bash
screen -d -m -S svr1 -t jonesy@svr1
ssh server1.linuxlaboratory.orgscreen -d -m -S svr2 -t jonesy@svr2
ssh server2.linuxlaboratory.orgscreen -d -m -S svr3 -t jonesy@svr3
ssh server3.linuxlaboratory.org
## Bonus (2)
We can also monitor/watch active screen sessions with the command:
screen -x [pid.tty.host]
*source: https://www.linux.com/news/sysadmin-sysadmin-beauty-screen/