Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

9.3.1 Manage remote sessions


May 24, 2021 That's what Linux should learn



Screen commands can do a lot of things: create session windows with the -S parameter, take the specified session offline with the -d parameter, resume the specified session with the -r parameter, restore all sessions at once with the -x parameter, display the currently existing session with the -ls parameter, delete the session that is not currently available with the -wipe parameter, and so on.

Below, create a session window with the name backup. Please keep an eye out for the moment you tap this command on the command line, the screen flashes quickly, and you're already in the screen service session, where any operation you run is recorded in the background.

A root@linuxprobe is returned as soon root@linuxprobe the command is executed. Although it doesn't look different than it did just now, you can actually see that the current session is working.

[root@linuxprobe ~]# screen -ls There is a screen on: 32230.backup (Attached) 1 Socket in /var/run/screen/S-root. It's also easy to exit a session by simply executing the exit command on the command line.

In root@linuxprobe production environment, it's not really necessary to create a session before you start working. You can use the screen command directly to execute the command you want to run, so that everything in the command is recorded and the screen session ends automatically when the command is executed.

root@linuxprobe To demonstrate the power of linuxprobe.com.txt screen's uninterrupted session service, let's create a session called linux and then force the window to close (which has the same effect as a sudden disconnection on a remote connection):

[root@linuxprobe ~]# screen -S linux [root@linuxprobe ~]# [root@linuxprobe ~]# tail -f /var/log/messages Feb 20 11:20:01 localhost systemd: Starting Session 2 of user root. F eb 20 11:20:01 localhost systemd: Started Session 2 of user root. F eb 20 11:21:19 localhost dbus-daemon: dbus[1124]: [system] Activating service name='com.redhat.SubscriptionManager' (using servicehelper) Feb 20 11:21:19 localhost dbus[1124]: [system] Activating service name='com.redhat.SubscriptionManager' (using servicehelper) Feb 20 11:21:19 localhost dbus-daemon: dbus[1124]: [system] Successfully activated service ' c om.redhat.SubscriptionManager' Feb 20 11:21:19 localhost dbus[1124]: [system] Successfully activated service 'com.redhat.SubscriptionManager' Feb 20 11:30:01 localhost systemd: Starting Session 3 of user root. F eb 20 11:30:01 localhost systemd: Started Session 3 of user root. F eb 20 11:30:43 localhost systemd: Starting Cleanup of Temporary Directories... F eb 20 11:30:43 localhost systemd: Started Cleanup of Temporary Directories. S ince the session window has just been closed, such an operation in traditional remote control must cause the running command to terminate abruptly, but not in the screen non-stop session service. All we have to do is look at the session name that just went offline and try to get back to work:

[root@linuxprobe ~]# screen -ls There is a screen on: 13469.linux (Detached) 1 Socket in /var/run/screen/S-root. [root@linuxprobe ~]# screen -r linux [root@linuxprobe ~]# [root@linuxprobe ~]# tail -f /var/log/messages Feb 20 11:20:01 localhost systemd: Starting Session 2 of user root. Feb 20 11:20:01 localhost systemd: Started Session 2 of user root. Feb 20 11:21:19 localhost dbus-daemon: dbus[1124]: [system] Activating service name='com.redhat.SubscriptionManager' (using servicehelper) Feb 20 11:21:19 localhost dbus[1124]: [system] Activating service name='com.redhat.SubscriptionManager' (using servicehelper) Feb 20 11:21:19 localhost dbus-daemon: dbus[1124]: [system] Successfully activated service 'com.redhat.SubscriptionManager' Feb 20 11:21:19 localhost dbus[1124]: [system] Successfully activated service 'com.redhat.SubscriptionManager' Feb 20 11:30:01 localhost systemd: Starting Session 3 of user root. Feb 20 11:30:01 localhost systemd: Started Session 3 of user root. Feb 20 11:30:43 localhost systemd: Starting Cleanup of Temporary Directories... Feb 20 11:30:43 localhost systemd: Started Cleanup of Temporary Directories. F eb 20 11:40:01 localhost systemd: Starting Session 4 of user root. F eb 20 11:40:01 localhost systemd: Started Session 4 of user root. I f we suddenly think of other things to deal with, we can also create a few more session windows to use together. I f you no longer use a session window during this time, you can set it to temporarily disconnect mode and then reconnect (attach) back when needed. During this time, programs running within the session window continue to execute.