|
|
|
@ -73,7 +73,7 @@ if [ "$DELETE" = "1" ] ; then
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Ignore -P if rsync is going to be used |
|
|
|
|
if [ "$RSYNC" = "1" -a "$PARALLEL" = "1" ] ; then |
|
|
|
|
if [ "$RSYNC" = "1" ] && [ "$PARALLEL" = "1" ] ; then |
|
|
|
|
echo "Cannot transfer in parallel when using rsync: ignoring -P." |
|
|
|
|
PARALLEL="" |
|
|
|
|
fi |
|
|
|
@ -82,13 +82,13 @@ fi
|
|
|
|
|
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp) |
|
|
|
|
PRSYNC=$(command -v parallel-rsync || command -v prsync) |
|
|
|
|
CLUSTERPING=$(command -v cluster-ping) |
|
|
|
|
if [ "$RSYNC" = "" -a "$PSCP" = "" ] ; then |
|
|
|
|
if [ -z "$RSYNC" ] && [ -z "$PSCP" ] ; then |
|
|
|
|
echo "Parallel SSH (pssh) is required for this script to work." |
|
|
|
|
exit 4 |
|
|
|
|
elif [ "$PRSYNC" = "" ] ; then |
|
|
|
|
elif [ -z "$PRSYNC" ] ; then |
|
|
|
|
echo "Parallel rsync (prsync) is required for this script to work." |
|
|
|
|
exit 5 |
|
|
|
|
elif [ "$CLUSTERPING" = "" ] ; then |
|
|
|
|
elif [ -z "$CLUSTERPING" ] ; then |
|
|
|
|
echo "cluster-ping (which should have been provided along with this" |
|
|
|
|
echo "script) is required for this script to work." |
|
|
|
|
exit 6 |
|
|
|
@ -96,7 +96,7 @@ fi
|
|
|
|
|
|
|
|
|
|
# Hosts' list file |
|
|
|
|
HOSTS_LIST_NAME="$1" |
|
|
|
|
if [ "$XDG_CONFIG_HOME" = "" ] ; then |
|
|
|
|
if [ -z "$XDG_CONFIG_HOME" ] ; then |
|
|
|
|
XDG_CONFIG_HOME="$HOME/.config" |
|
|
|
|
fi |
|
|
|
|
HOSTS="$XDG_CONFIG_HOME/cluster/${HOSTS_LIST_NAME}.lst" |
|
|
|
@ -108,7 +108,7 @@ if [ ! -f "$HOSTS" ] ; then
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Login |
|
|
|
|
if [ "$LOGIN" != "" ] ; then |
|
|
|
|
if [ -n "$LOGIN" ] ; then |
|
|
|
|
echo "Login: $LOGIN" |
|
|
|
|
SSH_LOGIN="${LOGIN}@" |
|
|
|
|
LOGIN="-l $LOGIN" |
|
|
|
@ -116,14 +116,15 @@ fi
|
|
|
|
|
|
|
|
|
|
# Test the connection to the first host and get the destination |
|
|
|
|
# directory (home directory of the remote user) |
|
|
|
|
FIRST_HOST=$($CLUSTERPING "$HOSTS_LIST_NAME" 2>/dev/null | sed -n "s/ is alive$//p" | head -n1) |
|
|
|
|
if [ "$FIRST_HOST" = "" ] ; then |
|
|
|
|
FIRST_HOST=$($CLUSTERPING "$HOSTS_LIST_NAME" 2>/dev/null \ |
|
|
|
|
| sed -n "s/ is alive$//p" | head -n1) |
|
|
|
|
if [ -z "$FIRST_HOST" ] ; then |
|
|
|
|
echo "None of the remote hosts is alive." |
|
|
|
|
exit 7 |
|
|
|
|
fi |
|
|
|
|
echo "Testing connection to $FIRST_HOST..." |
|
|
|
|
DEST_DIR="$(ssh ${SSH_LOGIN}${FIRST_HOST} 'echo $HOME' 2>/dev/null)" |
|
|
|
|
if [ "$DEST_DIR" = "" ] ; then |
|
|
|
|
DEST_DIR="$(ssh "${SSH_LOGIN}${FIRST_HOST}" 'echo $HOME' 2>/dev/null)" |
|
|
|
|
if [ -z "$DEST_DIR" ] ; then |
|
|
|
|
echo "Cannot connect to the first alive host. Aborting." |
|
|
|
|
exit 7 |
|
|
|
|
fi |
|
|
|
@ -131,6 +132,7 @@ echo "Destination directory: $DEST_DIR"
|
|
|
|
|
|
|
|
|
|
# Transfer the files in parallel... |
|
|
|
|
if [ "$PARALLEL" = "1" ] ; then |
|
|
|
|
# shellcheck disable=SC2086 |
|
|
|
|
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" "$DEST_DIR" |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
@ -142,8 +144,10 @@ for FILE in "$@" ; do
|
|
|
|
|
continue |
|
|
|
|
fi |
|
|
|
|
if [ "$RSYNC" = "1" ] ; then |
|
|
|
|
# shellcheck disable=SC2086 |
|
|
|
|
$PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR" |
|
|
|
|
else |
|
|
|
|
# shellcheck disable=SC2086 |
|
|
|
|
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR" |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|