aboutsummaryrefslogtreecommitdiff
path: root/bin/sta
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-31 00:20:32 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-31 00:20:32 +1200
commit8b8ae8cd71391996c137c90925796b132346524c (patch)
tree1739f8f7c43634976513f59525644602a04a986e /bin/sta
parentSet executable bit on paz(1) (diff)
downloaddotfiles-8b8ae8cd71391996c137c90925796b132346524c.tar.gz
dotfiles-8b8ae8cd71391996c137c90925796b132346524c.zip
Make sta(1) POSIX-compatible
Diffstat (limited to 'bin/sta')
-rwxr-xr-xbin/sta41
1 files changed, 7 insertions, 34 deletions
diff --git a/bin/sta b/bin/sta
index ced20cef..5d8ee825 100755
--- a/bin/sta
+++ b/bin/sta
@@ -1,34 +1,7 @@
-#!/usr/bin/env bash
-
-#
-# sta(1) -- Run a command on every hostname returned by sls(1) and print
-# the hostname if the command's return value was zero. Discard stdout, but do
-# print stderr.
-#
-# Author: Tom Ryder <tom@sanctum.geek.nz>
-# Copyright: 2014
-# License: Public domain
-#
-
-# Name self
-self=sta
-
-# Handle ^C interrupts
-trap 'trap - INT; kill -INT $$' INT
-
-# Bail if we couldn't find sls(1)
-hash sls || 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
- # shellcheck disable=SC2029
- if ssh -nq -- "$hostname" "$@" >/dev/null ; then
- printf '%s\n' "$hostname"
- fi
-done < <(sls)
+#!/bin/sh
+# Print list of sls(1) hostnames that return 0 when a connection is attempted
+# and the optional given command is run. Discard stdout, but preserve stderr.
+sls | while read -r hostname ; do
+ ssh -nq -- "$hostname" "$@" >/dev/null || continue
+ printf '%s\n' "$hostname"
+done