Use gsh to run the same command on many servers


Staff member
Oct 27, 2011
Reaction score
At some point you will find it very handy to be able to run the same command on multiple servers. Sure, you could just put a list of IPs in a file and run something against it using a for loop, but gsh is going to make your life much easier.

First off, i've used the old 'list of ips' way in the past - especially if I have an easy list of servers that are all the same and know that I want to group them all together. gsh, on the other hand, will allow you to run the same command on various servers sorted by category, similar to ansible.

You still need to maintain a list of your servers, but it's worth it. Also, you'll want to have ssh keys set up on each of the servers from your 'gsh-server'.

Some examples
Want to check the openssh version on each of your cent6 and cent7 machines?
gsh cent6+cent7 "rpm -q openssh"

How about uptime on all of your VPS?
gsh vps "uptime"

How about uptime on all of just the cent6 vps machines?
gsh vps^cent7 "uptime"

An example /etc/ghosts file
Each installation of gsh requires a valid /etc/ghosts file (yes.. you can pronounce it "gee hosts"). Here's an example one which ties in our examples from above:
# Hostname    Hardware    OS    vps        cent6    vps        cent7    metal    cent6

Download / Install it
You can download gsh from here:

Once you unpack it and cd into its directory, you can install it with:
perl Makefile.PL
make install

Then, Start your /etc/ghosts file. You can have as many categories as you like. Some popular ones can be location / dc, os, hardware, etc..

Have fun with it - and let us know how it goes!

Members online