DSH is Distributed Shell. It allows you to run shell commands on multiple servers at once and gather see their output in local terminal.

Install

Install  On Debian/Ubuntu

apt-get install dsh

Mac

brew install dsh

Config

You can use default config but we always add following to dsh config file:

Global config => /etc/dsh.conf

Local config =>  ~/.dsh/dsh.conf

remoteshell = ssh
showmachinenames = 1

Hostname List

Edit/create

Global list => /etc/dsh/machines.list

Local list =>  ~/.dsh/dsh/machines.list

Add hostnames, one on each line.

Please note that, you need to add SSH key’s separately (beforehand).

example.com
example.net

Usage

We need to pass actual command to dsh command with optional prameters:

Lets check uptime

 dsh -a uptime

You will see output as below

example.com: 18:07:18 up 294 days,  6:38,  3 users,  load average: 0.17, 0.26, 0.24
example.net: 18:09:47 up 9 days, 19:54,  1 user,  load average: 0.26, 0.2

-a denotes run for all hosts.

We can also pass -c which will create concurrent connections to all servers.

Grouping Hosts/Servers

You can make group and run dsh command on that group servers only.

You can add a file under group directory like below

Global settings => /etc/dsh/group/hello

Local settings =>  ~/.dsh/dsh/group/hello

Add list of hostnames. You can add multiple hostnames to groups

hello.com
hello.net
hello.org

Lets check uptime on hello group servers:

dsh -g hello uptime

Will display something like

hello.com: 18:11:45 up 9 days, 19:56,  0 users,  load average: 0.05, 0.18, 0.22
hello.net: 18:11:45 up 19 days, 19:56,  0 users,  load average: 0.15, 0.18, 0.22
hello.org: 18:11:45 up 119 days, 19:56,  0 users,  load average: 0.15, 1.8, 0.22

Web-Based Alternative

If you are looking for web-based service which does things like this, you may try https://commando.io/.  It has some really nice features and a free plan for 2 users.