ssh-to: Easily manage dozens or hundreds of machines with SSH

Hey software engineers! Do you manage servers? Lots of servers? Hate copying and pasting hostnames and IP addresses? Need a way to execute a command on each of a group of servers that you manage?

I developed an app which can help with those things, and my employer has graciously given me permission to open source it.

First, here’s the link:

https://github.com/comcast/ssh-to

And here’s how to download a copy:

git clone https://github.com/Comcast/ssh-to.git

Getting Started

In order to use this script, you’ll need to create a servers.json file:

./ssh-to --create

This will create a sample servers.json file in the current directory. You may want to then move that file to $HOME/.ssh-to-servers.json so that ssh-to can be run from any directory in the filesystem.

Next, to add hosts and hostgroups to the servers.json file:

./ssh-to --edit

This will bring up $EDITOR to edit the file. After you are done editing, exit the editor, and the validity of the JSON will be checked. If the JSON fails to validate, you’ll be prompted to hit ENTER to go back into the editor or ctrl-C to abort.

Using ssh-to

Going forward, here’s the syntax for using ssh-to in regular operation:

ssh-to [ --dump | --loop ] group [ host_number ] [ ssh_args ]

–dump prints out the hostname/IP address (or plural, if you just specify a group), which can be used in other scripts like so:

for HOST in $(ssh-to --dump hadoop)
do
   scp file.txt ${HOST}:/path/to/destination/
done

“But wait, there’s more!”

Using the –loop switch, this sets the way for other cool automations! Here’s an example:

ssh-to splunk --loop "yum install -y splunk; /opt/splunk/bin/splunk stop; /opt/splunk/bin/splunk start --answer-yes --no-prompt"

This would, on an existing Splunk cluster, perform rolling upgrades of Splunk on each machine in the cluster.

“Operators are standing by!”

Please, try out the tool and let me know what you think via email or in the comments below. Feedback, bugfixes, and suggestions for features are always welcome!

— Doug