aboutsummaryrefslogblamecommitdiff
path: root/bin/shock
blob: c578b6247237bc013633c79513ca5b653216cb69 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11


                   
                                                                            


                                                                             



                                         

















                                                    
                               



                                                    
#!/usr/bin/env bash

#
# shock(1) -- Run a command on every hostname returned by shoal(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=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
    # shellcheck disable=SC2029
    if ssh -nq -- "$hostname" "$@" >/dev/null ; then
        printf '%s\n' "$hostname"
    fi
done < <(shoal)