MUltihost SSH Wrapper, or mussh, is truly an old utility that you can still find to be of good use for today. At its core, mussh is just a shell script wrapper around SSH that allows you to execute the same command across multiple hosts either in sequence or parallel. The script has been filling a gap that until recently most CM tools have ignored: running one-off commands across your distributed systems.
When we have configuration management, why would we possibly want to do something outside of that? While it is true that you should be enforcing system state with a bigger hammer, sometimes you only need to perform a task once, or infrequently.
Want to enhance your skills to become master in DevOps Methodology, enroll in our DevOps Training
Take for example, NTP clock skew. I recently ran into an issue where I found that a service had a dramatically increased network queue time, after a hardware upgrade. NTP configuration and service state were being enforced through CM, so I knew that it was running. I wanted to verify that all the system clocks were synchronized, and I didn’t want to manually ssh to each of them.
$ mussh -l pi -m 2 -h rpi-1 rpi-2 -c ‘sudo ntpdate -u ntp.home’ pi@rpi-1: ntpdate: adjust time server ntp.home offset 0.0151 sec pi@rpi-2: ntpdate: adjust time server ntp.home offset 0.0006 sec
Whoa, that’s a long command. So let’s break it down.
Sync NTP across multiple hosts concurrently
-l pi # Set the ssh username
-m 2 # Run on two hosts concurrently
-h rpi-1 rpi-2 # Hostnames for the command
-c ‘sudo ntpdate -u ntp.home’ # Sync ntp with this peer
The resulting output is in the format of hostname: output of the command, which is useful when you run commands that you expect a single line from. You can optionally pass the -b flag to have output buffered by mussh, otherwise the output from all systems will display interwoven with each other, if you are expecting multiple lines of output per host.
Frequently asked Devops Interview Questions
We also make three assumptions in this example. The first is that you have a key-based ssh authentication working between your computer and the list of hosts (you are using keys, right?). You also need to have ssh-agent running and working, so you’re not prompted for your private key password for every host. Finally, this example assumes that the pi user is able to execute sudo on ntpdate without a password prompt, which works well for demos in a lab environment but is not a best practice for production.
Well, that’s all fine and dandy, but I don’t want to type all the server names in for every command! Luckily, mussh supports reading the hosts one line at a time out of a file with the -H option. So instead, grab them from whatever storage mechanism you have (flat-file, database, RESTful endpoint) and pipe them in!
$ grep “rpi-” servers.txt | mussh -l pi -H – -c ‘uptime’ pi@rpi-1: 21:12:54 up 4 days, 23:18, 1 user, load average: 0.00 pi@rpi-2: 21:12:54 up 4 days, 23:18, 1 user, load average: 0.00
In this snippet, I’m searching through a text file for my Raspberry Pi “servers” and sending those through mussh. The secret is in the -H –, which tells mussh that the file to read from is stdin.
Conclusion
We still have a lot to learn from the past about where we can go in the future. The tools of our past live on and inspire innovation, daring us to replace them with the next generation. Some of the tools discussed here have successors that are still in infancy. Some of them are still in active development and could use an influx of motivated developers to push them to the next level. All of them have contributed to getting us where we are today and deserve — if nothing else — a tip of the hat.
Are you looking to get trained on DevOps, we have the right course designed according to your needs. Our expert trainers help you gain the essential knowledge required for the latest industry needs. Join our DevOps Certification Training program from your nearest city.
DevOps Training Chennai, DevOps Training Dallas, DevOps Training Bangalore, DevOps Training London, DevOps Training Mumbai, DevOps Training Chicago, DevOps Training Gurgaon, DevOps Training Pune.
These courses are equipped with Live Instructor-Led Training, Industry Use cases, and hands-on live projects. Additionally, you get access to Free Mock Interviews, Job and Certification Assistance by Certified DevOps Trainers
Explore Devops Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
DevOps Training | Dec 17 to Jan 01 | View Details |
DevOps Training | Dec 21 to Jan 05 | View Details |
DevOps Training | Dec 24 to Jan 08 | View Details |
DevOps Training | Dec 28 to Jan 12 | View Details |
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.