May 212014
 

Original article by Linux Brigade

Ever have to check a list of Linux servers for various things like what version of CentOS they’re running, maybe how long each has been running to get an uptime report? You can and it’s very easy to get going with it with the command gsh

Group Shell (also called gsh) is a remote shell multiplexor. It lets you control many remote shells at once in a single shell. Unlike other commands dispatchers, it is interactive, so shells spawned on the remote hosts are persistent.
It requires only a SSH server on the remote hosts, or some other way to open a remote shell.


gsh allows you to run commands on multiple hosts by adding tags to the gsh command.

Important things to remember:

  • /etc/ghosts contains a list of all the servers and tags
  • gsh is a lot more fun once you’ve set up ssh keys to your servers

Examples to use:

List uptime on all servers in the linux group:

Check to see if an IP address was blocked with CSF by checking the csf and csfcluster groups/tags:

Unblock an IP and remove from /etc/csf.deny from all csf and csfcluster machines

Check the linux kernel version on all VPS machines running centos 5

Check cpanel version on all cpanel machines

The full readme is located here: http://outflux.net/unix/software/gsh/

Here’s an example /etc/ghosts file:

# Machines
#
# hostname         OS-Version Hardware OS  cp     security
1.linuxbrigade.com debian6 baremetal linux plesk  iptables
2.linuxbrigade.com centos5 vps       linux cpanel csfcluster
3.linuxbrigade.com debian7 baremetal linux plesk  iptables
4.linuxbrigade.com centos6 vps       linux cpanel csfcluster
5.linuxbrigade.com centos6 vps       linux cpanel csfcluster
6.linuxbrigade.com centos6 vps       linux nocp   denyhosts
7.linuxbrigade.com debian6 baremetal linux plesk  iptables
8.linuxbrigade.com centos6 baremetal linux cpanel csf
9.linuxbrigade.com centos5 vps       linux cpanel csf


Popular Posts:

Flattr this!

  5 Responses to “Run the same command on many Linux servers at once”

  1. I didn’t know this tool. I used “cssh” until now. I’m going to give gsh a try. Thanks for the article! As always, it is good reading material.

  2. Hmmm, I’ve always used something simple like this:
    for i in 1 2 3 4 5 6 7 8;do echo “XEN${i}”;ssh 1.1.1.3${i} apt-get upgrade -y ; done
    for i in 1 2 3 4 5 6 7 8;do echo “XEN${i}”;ssh 1.1.1.3${i} /etc/init.d/ssh restart ; done

    etc… might give this a go one day, depending on how well it works.
    Personally, I’d like to be able to open a bunck of terminal windows to a group of hosts, send the same command to all of them, and then interact with each individually, or as a group. Like a “group command line” as well as the normal individual command lines.

  3. And the last update to the application was on 2006? and seems like its dead.

  4. If you have a little money SecureCRT from Vandyke software is an awesome connection manager. I use it to manage around 600 linux VM’s and about 50 32 port serial concentrators.

  5. how to connect gsh if I using different ssh port?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*