From b8edd5536e9f824d75ac44bb57058b656e351535 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 2 May 2014 14:32:12 +1200 Subject: Add scatter(1), shoal(1), and shock(1) --- bin/scatter | 34 ++++++++++++++++++++++++++++++++++ bin/shoal | 15 +++++++++++++++ bin/shock | 30 ++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100755 bin/scatter create mode 100755 bin/shoal create mode 100755 bin/shock (limited to 'bin') diff --git a/bin/scatter b/bin/scatter new file mode 100755 index 00000000..5cb62e44 --- /dev/null +++ b/bin/scatter @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# +# scatter(1) -- Run a command on every hostname returned by shoal(1) and print +# both stdout and stderr, including allocating a pty with -t. +# +# Author: Tom Ryder +# Copyright: 2014 +# License: Public domain +# + +# Name self +self=scatter + +# Handle ^C interrupts +trap 'trap - INT; kill -INT $$' INT + +# Bail if we couldn't find shoal(1) +hash shoal || exit + +# Exit with usage method if no arguments given +if ! (($#)) ; then + printf 'USAGE: %s \n' "$self" >&2 + exit 1 +fi + +# Execute command, print both stdout and stderr, and use file descriptor 3 to +# avoid clobbering any of the standard streams +while read -r hostname <&3 ; do + printf '%s: %s\n' "$self" "$hostname" + ssh -qt -- "$hostname" "$@" + printf '\n' +done 3< <(shoal) + diff --git a/bin/shoal b/bin/shoal new file mode 100755 index 00000000..469ce487 --- /dev/null +++ b/bin/shoal @@ -0,0 +1,15 @@ +#!/bin/sh + +# +# shoal(1) -- Print all the non-wildcard Host names (first +# one per line) from an ssh_config(5) file, defaulting to +# $HOME/.ssh/config. +# +# Author: Tom Ryder +# Copyright: 2014 +# License: Public domain +# + +prog='$1 == "Host" && $2 !~ /[^a-z0-9_-]/ {print $2}' +awk "$prog" "${1:-$HOME/.ssh/config}" + diff --git a/bin/shock b/bin/shock new file mode 100755 index 00000000..0b61c52e --- /dev/null +++ b/bin/shock @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# +# shock(1) -- Run a command on every hostname returned by shock(1) and print +# the hostname if the command's return value was zero. Discard stdout, but do +# print stderr. +# + +# Name self +self=shock + +# Handle ^C interrupts +trap 'trap - INT; kill -INT $$' INT + +# Bail if we couldn't find shoal(1) +hash shoal || exit + +# Exit with usage method if no command given +if ! (($#)) ; then + printf 'USAGE: %s \n' "$self" >&2 + exit 1 +fi + +# Execute command, print hostname if it returns zero +while read -r hostname ; do + if ssh -nq -- "$hostname" "$@" >/dev/null ; then + printf '%s\n' "$hostname" + fi +done < <(shoal) + -- cgit v1.2.3