From 91ea519ae81c1e5cc371526f91c441d97c175065 Mon Sep 17 00:00:00 2001 From: Amber Date: Mon, 14 Mar 2022 21:26:00 +0100 Subject: [PATCH] syncloop improve logging --- syncloop.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/syncloop.sh b/syncloop.sh index b307b87..8aff1b9 100755 --- a/syncloop.sh +++ b/syncloop.sh @@ -63,7 +63,7 @@ synccycle() { if [ -f "$TMPQUEUEDELETES" ]; then ndeletes=$(wc -l < ${TMPQUEUEDELETES}) while [ $ndeletes -gt 0 ]; do - echo "Remote files to delete: ${GREEN}$(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')${ENDCOLOR}" + echo -e "Remote files to delete: $(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')" ssh $REMOTEHOST "rm -rf $(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')" # remove the first ndeletes lines flock $lock_deletes @@ -73,7 +73,7 @@ synccycle() { rm -f ${tmpfile} flock -u $lock_deletes ndeletes=$(wc -l < ${TMPQUEUEDELETES}) - echo "ndeletes: $ndeletes" + echo -e ${RED}DONE${ENDCOLOR} done fi @@ -81,8 +81,10 @@ synccycle() { if [ -f "$TMPQUEUEFILE" ]; then nqueue=$(wc -l < ${TMPQUEUEFILE}) while [ $nqueue -gt 0 ]; do - echo "${TMPQUEUEFILE} not empty consume ${nqueue} updates in queue" + #echo "${TMPQUEUEFILE} not empty consume ${nqueue} updates in queue" + echo -e "Sending to remote: ${GREEN}$(head -n ${nqueue} ${TMPQUEUEFILE} | tr '\n', ' ')${ENDCOLOR} ..." sync $LOCALPATH_HASH $LOCALPATH $REMOTEPATH + echo -e "${GREEN}DONE${ENDCOLOR}" # remove the first nqueue lines from queue flock $lock_queue tmpfile=$(mktemp) @@ -122,11 +124,15 @@ inotifywait -m -r -e create -e close_write -e move -e delete --exclude "\.swp|\. if [ $action = 'DELETE' ] || [ $action = 'DELETE,ISDIR' ] || [ $action = 'MOVED_FROM' ] || [ $action = 'MOVED_FROM,ISDIR' ]; then echo "Enqueue delete: $dir$file" flock $lock_deletes - echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${TMPQUEUEDELETES} + echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${TMPQUEUEDELETES} 1>/dev/null flock -u $lock_deletes else flock $lock_queue - echo "Add notify to queue: file '$file' in directory '$dir' for '$action'" | tee -a ${TMPQUEUEFILE} + ## add to queue only if not already in it + if [ $(grep -E ${file}$ ${TMPQUEUEFILE} | wc -l) -lt 1 ]; then + #echo "Add notify to queue: file '$file' in directory '$dir' for '$action'" | tee -a ${TMPQUEUEFILE} + echo ${dir}${file} | tee -a ${TMPQUEUEFILE} + fi flock -u $lock_queue fi done