From 4865f3c8c605b80732f2ff8fe4f2a5df7a3220d8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 30 Oct 2009 19:25:23 +0100 Subject: [PATCH] extend delete_from_file() to allow removal of suffix files Signed-off-by: Nico Schottelius --- ccollect.sh | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index f2396dc..08cf756 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -100,16 +100,22 @@ pcmd() fi } +# +# ssh-"feature": we cannot do '... read ...; ssh ...; < file', +# because ssh reads stdin! -n does not work -> does not ask for password +# Allow deletion for files with suffix and without suffix +# delete_from_file() { - # - # ssh-"feature": we cannot do '... read ...; ssh ...; < file', - # because ssh reads stdin! -n does not work -> does not ask for password - # file="$1"; shift - while read to_remove; do set -- "$@" "${ddir}/${to_remove}"; done < "${file}" + suffix="$1" # only set for delete_incomplete +# [ "$#" = 1 ] && suffix="$1" && shift + while read to_remove; do + set -- "$@" "${ddir}/${to_remove}" + [ "$suffix" ] && set -- "$@" "$(echo ${to_remove} | sed "s/$suffix\$//")" + done < "${file}" _techo "Removing $@ ..." - pcmd rm ${VVERBOSE} -rf "$@" || _exit_err "Removing $@ failed." + pcmd echo rm ${VVERBOSE} -rf "$@" || _exit_err "Removing $@ failed." } display_version() @@ -425,14 +431,29 @@ while [ "${i}" -lt "${no_sources}" ]; do # # Check: incomplete backups? (needs echo to remove newlines) # + # *.marker: not possible, creates an error, if no *.marker exists + # -> catch return value + + pcmd ls -1 "${ddir}/"*"${CMARKER}" > "${TMP}" 2>/dev/null; ret=$? + + if [ "$ret" -eq 0 ]; then + _techo "Incomplete backups: ${incomplete}" + if [ -f "${c_delete_incomplete}" ]; then + delete_from_file "${TMP}" + fi + fi + incomplete="$(echo \ $(pcmd ls -1 "${ddir}/" | \ - awk '/ENVIRON["CMARKER"]$/ { - print $0; - gsub(ENVIRON["CMARKER"]$,"",$0); - print $0 - }' | \ - tee "${TMP}"))" + awk ' + BEGIN { regexp=ENVIRON["CMARKER"] "$" } + $0 ~ regexp { + print $0; + gsub(ENVIRON["CMARKER"]$,"",$0); + print $0 + }' | tee "${TMP}"))" + +FIXME: stopped here! -> gsub broken if [ "${incomplete}" ]; then _techo "Incomplete backups: ${incomplete}"