aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2014-05-02 14:32:12 +1200
committerTom Ryder <tom@sanctum.geek.nz>2014-05-02 14:32:12 +1200
commitb8edd5536e9f824d75ac44bb57058b656e351535 (patch)
treedb785b79565667dd51b4135d87904accf7b20d05 /bin
parentRemove redundant export call for PATH (diff)
downloaddotfiles-b8edd5536e9f824d75ac44bb57058b656e351535.tar.gz
dotfiles-b8edd5536e9f824d75ac44bb57058b656e351535.zip
Add scatter(1), shoal(1), and shock(1)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/scatter34
-rwxr-xr-xbin/shoal15
-rwxr-xr-xbin/shock30
3 files changed, 79 insertions, 0 deletions
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 <tom@sanctum.geek.nz>
+# 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 <command>\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 <tom@sanctum.geek.nz>
+# 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 <command>\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)
+