Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. More ways to get the info! - we shoot all of our new original content out as well as random messages on Twitter and our newsletter!. Twitter | Newsletter
    Dismiss Notice

Use gsh to run the same command on many servers

Discussion in 'Linux Other' started by Rob, May 22, 2017.

  1. Rob

    Rob Administrator
    Staff Member

    Joined:
    Oct 27, 2011
    Messages:
    430
    Likes Received:
    919
    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'.


    (Log in to hide this advertisement)


    Some examples
    Want to check the openssh version on each of your cent6 and cent7 machines?
    Code:
    gsh cent6+cent7 "rpm -q openssh"
    How about uptime on all of your VPS?
    Code:
    gsh vps "uptime"
    How about uptime on all of just the cent6 vps machines?
    Code:
    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:
    Code:
    # Hostname    Hardware    OS
    abc.linuxforum.com    vps        cent6
    def.linuxforum.com    vps        cent7
    ghi.linuxforum.com    metal    cent6
    Download / Install it
    You can download gsh from here:
    http://outflux.net/unix/software/gsh/


    Once you unpack it and cd into its directory, you can install it with:
    Code:
    perl Makefile.PL
    make
    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!
     

Share This Page