#!/bin/sh # # multissh.sh, Copyright © 2013, 2019 Matteo Cypriani # (Formerly named cluster-run.sh) # # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. # # Run a command on a list of remote hosts using Parallel SSH. #set -x set -u # Exit codes readonly EXIT_SUCCESS=0 readonly EXIT_USAGE=127 readonly EXIT_HOSTS_LIST=6 print_usage() { echo "Usage: $0 [-l login] " } bad_usage() { err "$@" echo >&2 print_usage >&2 exit $EXIT_USAGE } err() { printf 'Error! ' >&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}" -- "$@"