From 36d2c4d703dce06033033ceed7811cd0a12a00c6 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 8 May 2018 01:36:04 +0200 Subject: [PATCH] remote-copy_gateway-config.sh: test if remote directory holds files to download. --- remote-copy_gateway-config.sh | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/remote-copy_gateway-config.sh b/remote-copy_gateway-config.sh index b3efba0..32f3f6c 100755 --- a/remote-copy_gateway-config.sh +++ b/remote-copy_gateway-config.sh @@ -12,6 +12,9 @@ backup_date="$(date +%Y-%m-%d-%H%M)" declare -a files_backuped_arr=() declare -a dirs_backuped_arr=() +declare -a rm_local_files_arr=() +declare -a rm_local_dirs_arr=() + # ---------- # Base Function(s) @@ -256,6 +259,43 @@ rm_unchanged_backup() { fi } +remove_local_files() { + if [[ ${#rm_local_files_arr[@]} -gt 0 ]] ; then + for _file in "${rm_local_files_arr[@]}" ; do + echononl "Remove local file '$(basename "$_file")' .." + if [[ -f "$_file" ]] ; then + rm "$_file" > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat "$log_file")" + fi + else + echo_skipped + fi + done + fi +} + +remove_local_dir() { + if [[ ${#rm_local_dirs_arr[@]} -gt 0 ]] ; then + for _dir in "${rm_local_dirs_arr[@]}" ; do + echononl "Remove local directory '$(basename "$_dir")' .." + if [[ -d "$_dir" ]] ; then + rm -rf "$_dir" > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat "$log_file")" + fi + else + echo_skipped + fi + done + fi +} manage_files() { @@ -517,6 +557,11 @@ if $terminal ; then echo "" fi +declare -i remote_dir_count="$(ssh gw-replacement.wf.netz "ls -A ${_network}-config 2> /dev/null | wc -l")" +if [[ $remote_dir_count -lt 1 ]]; then + fatal "Remote Directory is empty. Run \033[1mcopy_gateway-config.sh ${_network}\033[m on remote host first." +fi + mkdir -p $OFFICE_DIR cd $OFFICE_DIR