Monday, May 26, 2014

Run the same command on many Linux servers at once

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:
Here’s an example /etc/ghosts file:
# Machines
# hostname         OS-Version Hardware OS  cp     security debian6 baremetal linux plesk  iptables centos5 vps       linux cpanel csfcluster debian7 baremetal linux plesk  iptables centos6 vps       linux cpanel csfcluster centos6 vps       linux cpanel csfcluster centos6 vps       linux nocp   denyhosts debian6 baremetal linux plesk  iptables centos6 baremetal linux cpanel csf centos5 vps       linux cpanel csf

No comments:

Post a Comment