[ssh_tools] multiping: check for dependencies
Also some reformatting / modernization of the code.
This commit is contained in:
parent
8ae30d5e91
commit
410ac3789b
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# multiping.sh, Copyright © 2013 Matteo Cypriani <mcy@lm7.fr>
|
||||
# multiping.sh, Copyright © 2013, 2019 Matteo Cypriani <mcy@lm7.fr>
|
||||
# (Formerly named cluster-ping.sh)
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
|
@ -11,23 +11,40 @@
|
|||
#
|
||||
# Ping a list of remote hosts using fping.
|
||||
|
||||
#set -x
|
||||
set -u
|
||||
|
||||
readonly EXIT_USAGE=127
|
||||
readonly EXIT_DEPENDENCY=4
|
||||
readonly EXIT_HOSTS_LIST=6
|
||||
|
||||
err()
|
||||
{
|
||||
printf 'Error! ' >&2
|
||||
printf '%s\n' "$@" >&2
|
||||
}
|
||||
|
||||
# Check arguments
|
||||
if [ $# -ne 1 ] ; then
|
||||
echo "Usage: $0 <hosts_list>"
|
||||
exit 1
|
||||
echo "Usage: $0 <hosts_list>" >&2
|
||||
exit $EXIT_USAGE
|
||||
fi
|
||||
|
||||
# Hosts' list file
|
||||
if [ -z "$XDG_CONFIG_HOME" ] ; then
|
||||
XDG_CONFIG_HOME="$HOME/.config"
|
||||
FPING=$(command -v fping)
|
||||
if [ -z "$FPING" ] ; then
|
||||
err "fping is required for this script to work."
|
||||
exit $EXIT_DEPENDENCY
|
||||
fi
|
||||
|
||||
# Hosts list file
|
||||
[ -z ${XDG_CONFIG_HOME+x} ] && XDG_CONFIG_HOME="$HOME/.config"
|
||||
HOSTS="$XDG_CONFIG_HOME/ssh_tools/$1.lst"
|
||||
echo "Using file '$HOSTS' as hosts' list."
|
||||
echo "Using file '$HOSTS' as hosts list."
|
||||
if [ ! -f "$HOSTS" ] ; then
|
||||
echo "The hosts' list file doesn't exist or is not a regular file."
|
||||
exit 2
|
||||
err "The hosts list file doesn't exist or is not a regular file."
|
||||
exit $EXIT_HOSTS_LIST
|
||||
fi
|
||||
|
||||
# Go!
|
||||
# shellcheck disable=SC2046
|
||||
exec fping $(cat "$HOSTS") 2>/dev/null
|
||||
exec "$FPING" $(cat "$HOSTS") 2>/dev/null
|
||||
|
|
Loading…
Reference in New Issue