#! /bin/bash INDI_SERVER= INDI_USER= TARGET_SERVER= TARGET_LOCAL= USE_PACK=1 USE_UNPACK=1 # Limit band width to 1500kb/s BWLIMIT=1500 function usage() { echo "Copy fits from remote server to local" echo "V 0.1 (c) Alphamax 2019" echo "usage : $0 [-i] [-u] [-t] [-l] [-P] [-U]" echo " -i : INDI remote server. Must be either name or ip adress" echo " -u : Remote user login" echo " -t : Remote directory where you save the fits files" echo " -l : Local directory where the fits files will be copy" echo " -P : 1 for use remote fpack command before copy. 0 no use fpack command" echo " -U : 1 for use funpack command on local machine. 0 no use funpack command" echo " -h : print this help" exit 1 } while getopts "i:u:t:l:P:U:h:" option; do case $option in i) INDI_SERVER=${OPTARG} ;; u) INDI_USER=${OPTARG} ;; t) TARGET_SERVER=${OPTARG} ;; l) TARGET_LOCAL=${OPTARG} ;; P) USE_PACK=${OPTARG} ((USE_PACK == 0 || USE_PACK == 1)) || usage ;; U) USE_UNPACK=${OPTARG} ((USE_UNPACK == 0 || USE_UNPACK == 1)) || usage ;; B) BWLIMIT=${OPTARG} ;; h) usage exit 1 ;; *) usage exit 1 ;; esac done if [[ "$USE_PACK" == "1" ]]; then ssh -l $INDI_USER $INDI_SERVER "/usr/local/bin/fpack -r -D $TARGET_SERVER/*.fits" fi # \ # --quiet \ # --no-motd \ if [[ $? == 0 ]]; then rsync --bwlimit=$BWLIMIT --archive --recursive --remove-source-files --exclude=$TARGET_SERVER --quiet $INDI_USER@$INDI_SERVER:$TARGET_SERVER $TARGET_LOCAL if [[ "$USE_UNPACK" == "1" ]]; then /usr/local/bin/funpack -D $TARGET_LOCAL/*.fz fi fi exit $?