Skip to main content
CentOS

Replicate Commands Using Screen

By December 20, 2015September 12th, 2022No Comments

Replicate Commands Using screenLet’s learn how to replicate command using screen in Linux. The Linux screen command is a windows manager for the command line. Allowing multiple sessions to be open in the one terminal or pseudo-terminal. Making use of the command screen it is possible through the single terminal to emulate many terminals and switch easily between each session. In this tutorial, we look at how we can run Commands on many systems using screen in Linux.

Installing Screen

If screen is not already installed on your system then we can install screen using the command:

$ sudo yum install -y screen

Using Screen

With screen installed we can start screen using:

$ screen

Once in screen we can create more nested screen using the key sequence: ctrl+a c . We can return to the previous screen using ctrl+a p and ctrl+a n will take me back to the newly created screen.

If we have several screens open we can use: ctrl+a “ to display a list of open screens.

To close a screen we can enter the screen and then type exit.

Running Commands on Many Servers

With the single screen open we can open two new screens and connect to remote servers.

From the initial screen we will create a new screen and connect that screen to the server s1 via ssh:

ctrl+a c
ssh s1

From this screen window we can return to the master and create a new screen and connect this screen to the server s2:

ctrl+a p
ctrl+a c
ssh s2

We now have 3 screens open, one on the original server and one each connected to s1 and s2.

We can return to the original screen using:

ctrl+a "
Select screen 0 from the menu

From here we can install nmap, or run any command on all screens:

ctrl+a :
at “#” stuff “yum install -y nmap^M"

The # represents all screens Stuff is an actual command to stuff the screen buffer with a command. The command has ^M to represent us using the ENTER key when we want a command to run.

Yum will now run in each screen window.