[cluster] deploy: add -P option

The -P option allows to transfer the files in parallel rather than one
by one.
This commit is contained in:
Matteo Cypriani 2013-05-02 11:18:24 -04:00
parent 2639f9aece
commit 044f120fcc
2 changed files with 35 additions and 15 deletions

View File

@ -56,5 +56,8 @@ Dependency: parallel-ssh (pssh)
= cluster-deploy.sh =
Deploy one or more files in parallel on every host of the hosts' list.
By default, the files are transfered one by one, to be sure to notice
the errors for each file (bad permissions, out of space, etc.), but the
-P option allows to transfer them all together.
Dependency: parallel-scp (pscp)

View File

@ -9,32 +9,43 @@
# http://sam.zoy.org/wtfpl/COPYING for more details.
#
# Deploy files on a number of remote hosts using Parallel SCP.
#set -x
print_usage()
{
echo "Usage: $0 [-l login] <hosts_list> <file1> [file2 [...]]"
echo "Usage:"
echo " $0 [-P] [-l login] <hosts_list> <file1> [file2 [...]]"
echo "-P: transfer files in parallel instead of one by one."
}
# Do we have at least a host list and a file?
# Parse the optional arguments
while [ $# -gt 2 ] ; do
case $1 in
"-l")
LOGIN="$2"
shift
shift
;;
"-P")
PARALLEL=1
shift
;;
*)
break
;;
esac
done
# Do we still have at least a host list and a file?
# Note: if the program was wrongly called but still has 2 arguments, for
# example with "cluster-deploy -l root -P my_file", it will try to use
# "-P" as hosts' list and "my_file" as the file to be transfered.
if [ $# -lt 2 ] ; then
print_usage
exit 1
fi
# Parse the optional arguments
if [ "$1" = "-l" ] ; then
LOGIN="$2"
shift
shift
# Do we still have at least a host list and a file?
if [ $# -lt 2 ] ; then
print_usage
exit 3
fi
fi
# Check dependencies
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp)
if [ "$PSCP" = "" ] ; then
@ -53,6 +64,12 @@ if [ "$LOGIN" != "" ] ; then
LOGIN="-l $LOGIN"
fi
# Transfer the files in parallel...
if [ "$PARALLEL" = "1" ] ; then
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" ~
fi
# ... or one by one
for FILE in "$@" ; do
echo "Deploying '$FILE'..."
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" ~