Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- while getopts 'vxf:d:r:' opt; do
- case $opt in
- f) confDirList=$OPTARG ;;
- d) remoteHost=$OPTARG ;;
- r) remoteHost=$OPTARG ;;
- x) export TRACE=1; set -x ;;
- v) flBeVerbose=1 ;;
- esac
- done
- shift $((OPTIND-1))
- [[ $remoteHost ]] || {
- echo 'You must specify remote host to be synced to as argument of -r key' >&2
- exit 1
- }
- if [[ -t 0 ]]; then
- confDirList=${confDirList:-$1}
- [[ $confDirList && -e $confDirList && -f $confDirList && -r $confDirList ]] || {
- echo 'You must specify readable file as a first parameter or -f key argument (or do not specify anything at all and pass directory list on STDIN)' >&2
- exit 2
- }
- else
- confDirList='-'
- fi
- shopt -s extglob
- info_ () {
- [[ $flBeVerbose ]] && echo "$@"
- }
- while read -r d; do
- [[ -d $d ]] || {
- echo "$d is not a directory, skipping it" >&2
- continue
- }
- d=${d%%+(/)}
- info_ "Processing <<$d>>"
- { ssh ${remoteHost} "mkdir -p '$d'" && echo 'mkdir OK' >&2; } || echo 'mkdir FAIL' >&2
- rsync -a${flBeVerbose:+v} "${d}/" "${remoteHost}:${d}"
- done < <(cat "$confDirList" | sed -r -e '/^\s*(#.*)?$/d' -e 's%\s*(#.*)$%%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement