[ssh_tools] multissh: don't require pssh
This commit is contained in:
parent
4f007e1473
commit
a2f5e9a48a
|
@ -17,7 +17,6 @@ set -u
|
||||||
# Exit codes
|
# Exit codes
|
||||||
readonly EXIT_SUCCESS=0
|
readonly EXIT_SUCCESS=0
|
||||||
readonly EXIT_USAGE=127
|
readonly EXIT_USAGE=127
|
||||||
readonly EXIT_DEPENDENCY=4
|
|
||||||
readonly EXIT_HOSTS_LIST=6
|
readonly EXIT_HOSTS_LIST=6
|
||||||
|
|
||||||
print_usage()
|
print_usage()
|
||||||
|
@ -39,6 +38,23 @@ err()
|
||||||
printf '%s\n' "$@" >&2
|
printf '%s\n' "$@" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn()
|
||||||
|
{
|
||||||
|
printf 'Warning! ' >&2
|
||||||
|
printf '%s\n' "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_command()
|
||||||
|
{
|
||||||
|
grep -v '^#' "$HOSTS" | while read -r host ; do
|
||||||
|
[ -z "$host" ] && continue
|
||||||
|
echo "Executing command on '$host'..."
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
ssh ${LOGIN} "${host}" -- "$@" </dev/null
|
||||||
|
# Note: </dev/null is to prevent ssh from swallowing stdin (see SC2095).
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Do we have at least a host list and a command?
|
# Do we have at least a host list and a command?
|
||||||
[ $# -lt 2 ] && bad_usage "Wrong number of arguments."
|
[ $# -lt 2 ] && bad_usage "Wrong number of arguments."
|
||||||
|
|
||||||
|
@ -56,8 +72,7 @@ fi
|
||||||
# Check dependencies
|
# Check dependencies
|
||||||
PSSH=$(command -v parallel-ssh || command -v pssh)
|
PSSH=$(command -v parallel-ssh || command -v pssh)
|
||||||
if [ -z "$PSSH" ] ; then
|
if [ -z "$PSSH" ] ; then
|
||||||
err "Parallel SSH (pssh) is required for this script to work."
|
warn "Parallel SSH (pssh) is not available. Install it for best results."
|
||||||
exit $EXIT_DEPENDENCY
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Hosts list file
|
# Hosts list file
|
||||||
|
@ -79,5 +94,9 @@ fi
|
||||||
|
|
||||||
echo "Command:" "$@"
|
echo "Command:" "$@"
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
if [ -n "$PSSH" ] ; then
|
||||||
exec $PSSH --print $LOGIN -h "$HOSTS" -- "$@"
|
# shellcheck disable=SC2086
|
||||||
|
exec $PSSH --print $LOGIN -h "$HOSTS" -- "$@"
|
||||||
|
else
|
||||||
|
ssh_command "$@"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue