From 17ca9b1630c7e4b9918819066477879ea4c56e4b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 9 Feb 2012 15:45:29 +0100 Subject: [PATCH] blog: how-to-find-and-execute-stuff-on-all-hosts Signed-off-by: Nico Schottelius --- ...o-find-and-execute-stuff-on-all-hosts.mdwn | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 blog/how-to-find-and-execute-stuff-on-all-hosts.mdwn diff --git a/blog/how-to-find-and-execute-stuff-on-all-hosts.mdwn b/blog/how-to-find-and-execute-stuff-on-all-hosts.mdwn new file mode 100644 index 00000000..b32627ab --- /dev/null +++ b/blog/how-to-find-and-execute-stuff-on-all-hosts.mdwn @@ -0,0 +1,27 @@ +[[!meta title="How to find and execute stuff on all hosts?"]] + +## Motivation + +Assume that you are managing a pretty large infrastructure of hosts, +sometimes there is a need to execute a command on all of them. + +The big question is, where to find out, which hosts exist. + +## Solution + +The usual approach is to invent some kind of centralised daemon that collects +or searches for available hosts. There is a way simpler solution available in +my situation, which may help you as well: +We do have a monitoring infrastructure, to which all hosts transmit their +configuration. The configuration is stored containing the full hostname +(like **foo.bar.local.ch**) plus the .cfg suffix. + +Thus a script that can be used to execute something on all hosts (sequentially though) +can look like this: + + for host in $(ssh monitoring01 "cd /opt/icinga/etc/hosts.d; ls"); do + host=${host%.cfg} + ssh "root@$host" "$@" + done + +[[!tag sysadmin localch unix]]