#!/bin/bash while getopts "ndv" opt; do case $opt in d) FLAGS="$FLAGS --delete";; n) FLAGS="$FLAGS --dry-run";; v) FLAGS="$FLAGS -v";; esac done shift $(($OPTIND -1)) LIST=($@); HOSTS=${LIST[@]:0:${#LIST[@]}-1} FILE=${LIST[@]:${#LIST[@]}-1} FILE=$(rel2abs $FILE) RFILE=$(dirname $FILE) [ -n "$HOSTS" ] && [ -n "$FILE" ] || { echo "Usage: $(basename $0) HOST[ HOST[ HOST[...]]] FILE" exit 1; } echo "HOSTS $HOSTS" echo "FILE $FILE" echo "TO $RFILE" for n in $HOSTS; do rsync $FLAGS -e ssh -lzrptog $n:$RFILE $FILE done