diff --git a/cluster/README b/cluster/README index b08874d..bc04b4b 100644 --- a/cluster/README +++ b/cluster/README @@ -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) diff --git a/cluster/cluster-deploy.sh b/cluster/cluster-deploy.sh index 8c89381..05d1e91 100755 --- a/cluster/cluster-deploy.sh +++ b/cluster/cluster-deploy.sh @@ -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] [file2 [...]]" + echo "Usage:" + echo " $0 [-P] [-l login] [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" ~