This tutorial explains how to run same command on multiple Linux servers in one go. Here I will talk about a simple command line tool for Linux admins that can run same command on multiple configured servers. Here it opens a central console and XTERM sessions for each server you configure. Whatever command you run in the central console, it will be sent to all the logged in servers. You just have to configure the tool in the beginning and then you are done. It can easily be setup on Ubuntu, CentOS, and Fedora like distributions to manage servers from one place.
If you are administrator then you frequently have to run some commands on servers you manage. Most of the times, those commands are same and you have to follow the sequential manner. There are some tools for parallel processing but not everyone is aware of them. The best tool that you can use for this work is Cluster SSH(cssh) that I have mentioned here. Here you just need to get ready the server configuration file that contains the host names. There are some other things that you can learn in its docs which will help you manage the server configurations.
How to Run Same Command on Multiple Linux Servers in One Go?
Based on the server that you have, you can install it with one simple command. I have Debian based distro, so I installed it using apt-get. This is open source tool as well and you can check out its GitHub page from here and there you can see more in the project readme on GitHub from here. The command to install it on other distos is mentioned there.
sudo apt-get install clusterssh
Now, you create a “home/.clusterssh/clusters” directory and create a configuration file(clusters). Here you basically have to define the host names of the servers you want to manage with tags. You can specify the server address with username there but that is optional. You can specify the server names in the manner shown in the screenshot below.
Now, it’s time to start connecting to the servers. You just run the following command with the tag specified. Since, I want to connect to two of my dev servers, so I have created a “dev” tag there. You just run it and then two XTERM terminals will open with one central console. You can see the screenshot below.
cssh dev
Now, you can enter the command you want to send to configured servers. If you have the same passwords then you can enter and get access into the remote servers. Whatever you type in the tiny central console will be visible in the opened XTERM terminals. Run any command you will notice that it will be issues to all the connected terminal automatically. In addition to this, you can add some other things in the command using the central console window such as a random number.
In this way, you can simply use this simple tool to connect all remote servers via SSH. And you can do parallel processing with ease. You can issue same command to all the servers it will take the same amount of time that it would have taken if you’d have done it in traditional way.
Closing thoughts
If you have multiple servers to manage then you need a parallel processing tool. It is waste of time to open one session for each remote server in the terminal and then run the command. With the Cluster SSH tool, you can do this efficiently. You just install it and configure it once and then use it with ease. This post will be enough to get started with this. If you want to see some other advanced options then you can simply head to its GitHub page.