[ssh_tools] multicopy: don't require multiping

This commit is contained in:
Matteo Cypriani 2019-10-21 16:37:56 +02:00
parent 2b47bb65d2
commit eed73bf99f
2 changed files with 18 additions and 12 deletions

View File

@ -95,8 +95,8 @@ remote files that are not in the local copy will be deleted (rsync's
Please note that unlike rsync, prsync cannot handle multiple local files, Please note that unlike rsync, prsync cannot handle multiple local files,
therefore the `-P` option is ignored when passed along with `-r` or `-R`. therefore the `-P` option is ignored when passed along with `-r` or `-R`.
**Dependencies**: `parallel-scp` (`pscp`), `parallel-rsync` (`prsync`), **Dependencies (optional)**: `parallel-scp` (`pscp`), `parallel-rsync`
`multiping` (see above) (`prsync`), `multiping` (see above)
**Ansible replacement**: use Ansible `copy` module. See also modules `fetch` **Ansible replacement**: use Ansible `copy` module. See also modules `fetch`
(to retrieve files instead of pushing them), `synchronize`, `rsync` and (to retrieve files instead of pushing them), `synchronize`, `rsync` and

View File

@ -129,9 +129,9 @@ fi
MULTIPING=$(command -v multiping) MULTIPING=$(command -v multiping)
if [ -z "$MULTIPING" ] ; then if [ -z "$MULTIPING" ] ; then
err "multiping (which should have been provided along with this" \ warn "multiping (which should have been provided along with this" \
"script) is required for this script to work." "script) is not available. For best results, make sure it is" \
exit $EXIT_DEPENDENCY "reachable from your PATH."
fi fi
# Hosts list file # Hosts list file
@ -153,14 +153,20 @@ if [ -n "$LOGIN" ] ; then
LOGIN="-l $LOGIN" LOGIN="-l $LOGIN"
fi fi
# Test the connection to the first alive host and get the destination # Test the connection to the first alive host
# directory (home directory of the remote user) if [ -n "$MULTIPING" ] ; then
FIRST_HOST=$($MULTIPING "$HOSTS_LIST_NAME" 2>/dev/null \ FIRST_HOST=$($MULTIPING "$HOSTS_LIST_NAME" 2>/dev/null \
| sed -n "s/ is alive$//p" | head -n1) | sed -n "s/ is alive$//p" | head -n1)
if [ -z "$FIRST_HOST" ] ; then if [ -z "$FIRST_HOST" ] ; then
err "None of the remote hosts is alive." err "None of the remote hosts is alive."
exit $EXIT_HOSTS_DEAD exit $EXIT_HOSTS_DEAD
fi
else # multiping is not available
warn "multiping is not available, using the first host in the hosts list."
FIRST_HOST="$(grep -v '^#' "$HOSTS" | head -n 1)"
fi fi
# Get the destination directory (home directory of the remote user)
echo "Testing connection to $FIRST_HOST..." echo "Testing connection to $FIRST_HOST..."
DEST_DIR="$(ssh "${SSH_LOGIN}${FIRST_HOST}" 'echo $HOME' 2>/dev/null)" DEST_DIR="$(ssh "${SSH_LOGIN}${FIRST_HOST}" 'echo $HOME' 2>/dev/null)"
if [ -z "$DEST_DIR" ] ; then if [ -z "$DEST_DIR" ] ; then