aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-31 00:10:12 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-31 00:14:17 +1200
commitd0c4a7edb5527dbe047e65a838b9cb4426ccd798 (patch)
treefb7e6dbf267c6476b3d15889948d02e5e6778e95
parentDisable false positive shellcheck in spr(1) (diff)
downloaddotfiles-d0c4a7edb5527dbe047e65a838b9cb4426ccd798.tar.gz
dotfiles-d0c4a7edb5527dbe047e65a838b9cb4426ccd798.zip
Reimplement sra(1) in POSIX sh
Also allows no command, to just open a shell
-rwxr-xr-xbin/sra42
-rw-r--r--man/man1/sra.16
2 files changed, 11 insertions, 37 deletions
diff --git a/bin/sra b/bin/sra
index 64ccb2ae..6c281918 100755
--- a/bin/sra
+++ b/bin/sra
@@ -1,34 +1,8 @@
-#!/usr/bin/env bash
-
-#
-# sra(1) -- Run a command on every hostname returned by sls(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=sra
-
-# 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 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"
- # shellcheck disable=SC2029
- ssh -qt -- "$hostname" "$@"
- printf '\n'
-done 3< <(sls)
+#!/bin/sh
+# Run ssh(1) with an optional command on every host in sls(1) output
+# Use FD3 to keep a reference to the script's stdin for the ssh(1) calls
+exec 3<&0
+sls | while read -r hostname ; do
+ printf 'sra: %s\n' "$hostname"
+ ssh -qt -- "$hostname" "$@" <&3 # shellcheck disable=SC2029
+done
diff --git a/man/man1/sra.1 b/man/man1/sra.1
index 3ddc7ac7..db4d1abd 100644
--- a/man/man1/sra.1
+++ b/man/man1/sra.1
@@ -4,11 +4,11 @@
\- run a command on sls(1) hosts
.SH SYNOPSIS
.B sra
-.I COMMAND
+.I [COMMAND]
.SH DESCRIPTION
.B sra
-runs a nominated command on all the hosts returned by sls(1), and prints the
-hostname, stdout, and stderr for each call.
+opens a secure shell or runs a command with ssh(1) on all the hosts returned by
+sls(1).
.SH SEE ALSO
sta(1), sls(1)
.SH AUTHOR