[cluster] minor improvements & shellcheck
This commit is contained in:
parent
ae8456fa96
commit
b00b2eb16b
|
@ -73,7 +73,7 @@ if [ "$DELETE" = "1" ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ignore -P if rsync is going to be used
|
# 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."
|
echo "Cannot transfer in parallel when using rsync: ignoring -P."
|
||||||
PARALLEL=""
|
PARALLEL=""
|
||||||
fi
|
fi
|
||||||
|
@ -82,13 +82,13 @@ fi
|
||||||
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp)
|
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp)
|
||||||
PRSYNC=$(command -v parallel-rsync || command -v prsync)
|
PRSYNC=$(command -v parallel-rsync || command -v prsync)
|
||||||
CLUSTERPING=$(command -v cluster-ping)
|
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."
|
echo "Parallel SSH (pssh) is required for this script to work."
|
||||||
exit 4
|
exit 4
|
||||||
elif [ "$PRSYNC" = "" ] ; then
|
elif [ -z "$PRSYNC" ] ; then
|
||||||
echo "Parallel rsync (prsync) is required for this script to work."
|
echo "Parallel rsync (prsync) is required for this script to work."
|
||||||
exit 5
|
exit 5
|
||||||
elif [ "$CLUSTERPING" = "" ] ; then
|
elif [ -z "$CLUSTERPING" ] ; then
|
||||||
echo "cluster-ping (which should have been provided along with this"
|
echo "cluster-ping (which should have been provided along with this"
|
||||||
echo "script) is required for this script to work."
|
echo "script) is required for this script to work."
|
||||||
exit 6
|
exit 6
|
||||||
|
@ -96,7 +96,7 @@ fi
|
||||||
|
|
||||||
# Hosts' list file
|
# Hosts' list file
|
||||||
HOSTS_LIST_NAME="$1"
|
HOSTS_LIST_NAME="$1"
|
||||||
if [ "$XDG_CONFIG_HOME" = "" ] ; then
|
if [ -z "$XDG_CONFIG_HOME" ] ; then
|
||||||
XDG_CONFIG_HOME="$HOME/.config"
|
XDG_CONFIG_HOME="$HOME/.config"
|
||||||
fi
|
fi
|
||||||
HOSTS="$XDG_CONFIG_HOME/cluster/${HOSTS_LIST_NAME}.lst"
|
HOSTS="$XDG_CONFIG_HOME/cluster/${HOSTS_LIST_NAME}.lst"
|
||||||
|
@ -108,7 +108,7 @@ if [ ! -f "$HOSTS" ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Login
|
# Login
|
||||||
if [ "$LOGIN" != "" ] ; then
|
if [ -n "$LOGIN" ] ; then
|
||||||
echo "Login: $LOGIN"
|
echo "Login: $LOGIN"
|
||||||
SSH_LOGIN="${LOGIN}@"
|
SSH_LOGIN="${LOGIN}@"
|
||||||
LOGIN="-l $LOGIN"
|
LOGIN="-l $LOGIN"
|
||||||
|
@ -116,14 +116,15 @@ fi
|
||||||
|
|
||||||
# Test the connection to the first host and get the destination
|
# Test the connection to the first host and get the destination
|
||||||
# directory (home directory of the remote user)
|
# directory (home directory of the remote user)
|
||||||
FIRST_HOST=$($CLUSTERPING "$HOSTS_LIST_NAME" 2>/dev/null | sed -n "s/ is alive$//p" | head -n1)
|
FIRST_HOST=$($CLUSTERPING "$HOSTS_LIST_NAME" 2>/dev/null \
|
||||||
if [ "$FIRST_HOST" = "" ] ; then
|
| sed -n "s/ is alive$//p" | head -n1)
|
||||||
|
if [ -z "$FIRST_HOST" ] ; then
|
||||||
echo "None of the remote hosts is alive."
|
echo "None of the remote hosts is alive."
|
||||||
exit 7
|
exit 7
|
||||||
fi
|
fi
|
||||||
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 [ "$DEST_DIR" = "" ] ; then
|
if [ -z "$DEST_DIR" ] ; then
|
||||||
echo "Cannot connect to the first alive host. Aborting."
|
echo "Cannot connect to the first alive host. Aborting."
|
||||||
exit 7
|
exit 7
|
||||||
fi
|
fi
|
||||||
|
@ -131,6 +132,7 @@ echo "Destination directory: $DEST_DIR"
|
||||||
|
|
||||||
# Transfer the files in parallel...
|
# Transfer the files in parallel...
|
||||||
if [ "$PARALLEL" = "1" ] ; then
|
if [ "$PARALLEL" = "1" ] ; then
|
||||||
|
# shellcheck disable=SC2086
|
||||||
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" "$DEST_DIR"
|
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" "$DEST_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -142,8 +144,10 @@ for FILE in "$@" ; do
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if [ "$RSYNC" = "1" ] ; then
|
if [ "$RSYNC" = "1" ] ; then
|
||||||
|
# shellcheck disable=SC2086
|
||||||
$PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
$PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
||||||
else
|
else
|
||||||
|
# shellcheck disable=SC2086
|
||||||
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
@ -17,7 +17,7 @@ if [ $# -ne 1 ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Hosts' list file
|
# Hosts' list file
|
||||||
if [ "$XDG_CONFIG_HOME" = "" ] ; then
|
if [ -z "$XDG_CONFIG_HOME" ] ; then
|
||||||
XDG_CONFIG_HOME="$HOME/.config"
|
XDG_CONFIG_HOME="$HOME/.config"
|
||||||
fi
|
fi
|
||||||
HOSTS="$XDG_CONFIG_HOME/cluster/$1.lst"
|
HOSTS="$XDG_CONFIG_HOME/cluster/$1.lst"
|
||||||
|
@ -28,4 +28,5 @@ if [ ! -f "$HOSTS" ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Go!
|
# Go!
|
||||||
|
# shellcheck disable=SC2046
|
||||||
exec fping $(cat "$HOSTS") 2>/dev/null
|
exec fping $(cat "$HOSTS") 2>/dev/null
|
||||||
|
|
|
@ -19,7 +19,7 @@ print_usage()
|
||||||
|
|
||||||
# Do we have at least a host list and a command?
|
# Do we have at least a host list and a command?
|
||||||
if [ $# -lt 2 ] ; then
|
if [ $# -lt 2 ] ; then
|
||||||
print_usage
|
print_usage >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -38,13 +38,13 @@ fi
|
||||||
|
|
||||||
# Check dependencies
|
# Check dependencies
|
||||||
PSSH=$(command -v parallel-ssh || command -v pssh)
|
PSSH=$(command -v parallel-ssh || command -v pssh)
|
||||||
if [ "$PSSH" = "" ] ; then
|
if [ -z "$PSSH" ] ; then
|
||||||
echo "Parallel SSH (pssh) is required for this script to work."
|
echo "Parallel SSH (pssh) is required for this script to work."
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Hosts' list file
|
# Hosts' list file
|
||||||
if [ "$XDG_CONFIG_HOME" = "" ] ; then
|
if [ -z "$XDG_CONFIG_HOME" ] ; then
|
||||||
XDG_CONFIG_HOME="$HOME/.config"
|
XDG_CONFIG_HOME="$HOME/.config"
|
||||||
fi
|
fi
|
||||||
HOSTS="$XDG_CONFIG_HOME/cluster/$1.lst"
|
HOSTS="$XDG_CONFIG_HOME/cluster/$1.lst"
|
||||||
|
@ -56,11 +56,12 @@ if [ ! -f "$HOSTS" ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Login
|
# Login
|
||||||
if [ "$LOGIN" != "" ] ; then
|
if [ -n "$LOGIN" ] ; then
|
||||||
echo "Login: $LOGIN"
|
echo "Login: $LOGIN"
|
||||||
LOGIN="-l $LOGIN"
|
LOGIN="-l $LOGIN"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Command:" "$@"
|
echo "Command:" "$@"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
exec $PSSH --print $LOGIN -h "$HOSTS" -- "$@"
|
exec $PSSH --print $LOGIN -h "$HOSTS" -- "$@"
|
||||||
|
|
|
@ -35,25 +35,26 @@ elif [ $# -ne 1 ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Hosts' list file
|
# Hosts' list file
|
||||||
if [ "$XDG_CONFIG_HOME" = "" ] ; then
|
if [ -z "$XDG_CONFIG_HOME" ] ; then
|
||||||
XDG_CONFIG_HOME="$HOME/.config"
|
XDG_CONFIG_HOME="$HOME/.config"
|
||||||
fi
|
fi
|
||||||
HOSTS="$XDG_CONFIG_HOME/cluster/$1.lst"
|
HOSTS_FILE="$XDG_CONFIG_HOME/cluster/$1.lst"
|
||||||
shift
|
shift
|
||||||
echo "Using file '$HOSTS' as hosts' list."
|
echo "Using file '$HOSTS_FILE' as hosts' list."
|
||||||
if [ ! -f "$HOSTS" ] ; then
|
if [ ! -f "$HOSTS_FILE" ] ; then
|
||||||
echo "The hosts' list file doesn't exist or is not a regular file."
|
echo "The hosts' list file doesn't exist or is not a regular file."
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Login
|
# Login
|
||||||
if [ "$LOGIN" != "" ] ; then
|
if [ -n "$LOGIN" ] ; then
|
||||||
echo "Login: $LOGIN"
|
echo "Login: $LOGIN"
|
||||||
LOGIN="${LOGIN}@"
|
LOGIN="${LOGIN}@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the screen tabs
|
# Create the screen tabs
|
||||||
for HOST in $(cat "$HOSTS") ; do
|
while read -r HOST ; do
|
||||||
SSH="ssh ${LOGIN}${HOST}"
|
SSH="ssh ${LOGIN}${HOST}"
|
||||||
|
# shellcheck disable=SC2086
|
||||||
screen -t "$SSH" $SSH
|
screen -t "$SSH" $SSH
|
||||||
done
|
done <"$HOSTS_FILE"
|
||||||
|
|
Loading…
Reference in New Issue