diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-31 00:20:32 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-31 00:20:32 +1200 |
commit | 8b8ae8cd71391996c137c90925796b132346524c (patch) | |
tree | 1739f8f7c43634976513f59525644602a04a986e /bin/sta | |
parent | Set executable bit on paz(1) (diff) | |
download | dotfiles-8b8ae8cd71391996c137c90925796b132346524c.tar.gz dotfiles-8b8ae8cd71391996c137c90925796b132346524c.zip |
Make sta(1) POSIX-compatible
Diffstat (limited to 'bin/sta')
-rwxr-xr-x | bin/sta | 41 |
1 files changed, 7 insertions, 34 deletions
@@ -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 |