aboutsummaryrefslogtreecommitdiff
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
parentSet executable bit on paz(1) (diff)
downloaddotfiles-8b8ae8cd71391996c137c90925796b132346524c.tar.gz
dotfiles-8b8ae8cd71391996c137c90925796b132346524c.zip
Make sta(1) POSIX-compatible
-rwxr-xr-xbin/sta41
-rw-r--r--man/man1/sta.19
2 files changed, 12 insertions, 38 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
diff --git a/man/man1/sta.1 b/man/man1/sta.1
index 49d8bcbd..0a5b82c0 100644
--- a/man/man1/sta.1
+++ b/man/man1/sta.1
@@ -4,12 +4,13 @@
\- run a command on sls(1) hosts and print the hostname if successful
.SH SYNOPSIS
.B sta
-.I COMMAND
+.I [COMMAND]
.SH DESCRIPTION
.B sta
-runs a nominated command on all the hosts returned by sls(1), and prints the
-hostname if the command has an exit value of 0. The stdout from the commands is
-discarded.
+attempts a connection and optionally runs a nominated command on all the hosts
+returned by sls(1), and prints the hostname if connected and if the optional
+command has an exit value of 0. The stdout from the commands is discarded, but
+stderr is shown.
.SH SEE ALSO
sra(1), sls(1)
.SH AUTHOR