I call this sshtomany:
#!/bin/bash cmd="$*" cmd="${cmd/#* . /}" [ "$cmd" = "$*" ] && echo "Usage: $0 [HOSTS] . [COMMAND]" && exit 127 while [ "$1" != . ] && ssh $1 -vt $cmd ; do echo Success at "$1" shift done
clusterssh and its emacs equivalent are quite handy if you want to execute commands simultaneously and fairly graphically.
The various versions of dsh and dssh are flexible command-line tools.
But sshtomany will do 90% of simple jobs by running the same ssh command on a list of hosts, one after another.
What’s wrong with func? 🙂
https://fedorahosted.org/func/
Sort of related, take a look at http://www.netfort.gr.jp/~dancer/software/dsh.html.en
Try out Ticketmaster’s gplv3 “onall”. There isn’t much better if you want to run a command on say… 400 or more hosts.
https://code.ticketmaster.com/trac/browser/onall/trunk/onall
An easy example would be:
host -l linux.yourdomain.com internal.dns.server.that.lets.you.axfr | awk ‘^spare/{print $1}’ > list-of-lots-of-servers.txt
onall -f list-of-lots-of-servers.txt “uname -r”
grep -v ‘lax’ list-of-lots-of-servers.txt | onall “ps -efH | grep badguy”
The biggest advantage this has over
for i in $(cat servers.txt); do
ssh ….
done
is mainly that it will connect out to hosts asynchronously in batches of 20 at a time (configurable) and return the results to you as they come in. Real good stuff.
What’s wrong with func seems to be that it supports only fedora (it says), it’s another subsystem to maintain and it seems to require writing modules before I can start using it for new tasks, but maybe I don’t understand it.
I didn’t see onall before. I don’t think it does serial interactive invocation, which is useful for my group of slightly awkward hosts – note the -t option I use for ssh. Also, can you understand batches of results at a time? Examples of the output would be interesting.
As mentioned, I looked at dsh. I didn’t use it because not all of my workstations run debian. I followed the link to dsh 2.0 and found what I thought was a dead project. Again, I’m not sure about serial interactive invocation.