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. I’ve evenwritten about it. gsh, on the other hand, will allow you to run the same command on various servers sorted by category.
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’.
Want to check the openssh version on each of your cent6 and cent7 machines?
gshcent6+cent7 "rpm -q openssh"
How about uptime on all of your VPS?
How about uptime on all of just the cent6 vps machines?
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 abc.linuxos.provpscent6 def.linuxos.provpscent7 ghi.linuxos.prometalcent6
Download / Install it
You can download gsh from here:
Once you unpack it and cd into its directory, you can install it with:
perlMakefile.PL make makeinstall
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!
转载本站任何文章请注明：转载至神刀安全网，谢谢神刀安全网 » Use gsh to run the same command on multiple servers