From 55f2cd73bb0b235ddfbcd451b13bef88dd4f573b Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Wed, 14 Feb 2024 13:46:09 +0100
Subject: [PATCH] update status

---
 rest_pruner.sh | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/rest_pruner.sh b/rest_pruner.sh
index 8fbf8d7..6e814ce 100755
--- a/rest_pruner.sh
+++ b/rest_pruner.sh
@@ -7,11 +7,12 @@
 # 2024-02-01  v0.1  <axel.hahn@unibe.ch>  first lines
 # 2024-02-02  v0.2  <axel.hahn@unibe.ch>  add: timer, skip file, skin N days, limit process time, stats
 # 2024-02-03  v0.3  <axel.hahn@unibe.ch>  enable cache dir; unlock before pruning
+# 2024-02-14  v0.4  <axel.hahn@unibe.ch>  update status
 # ======================================================================
 
 
 cd "$( dirname $0 )" || exit
-_version=0.3
+_version=0.4
 logdir=_last_prune
 
 prune_basedir=
@@ -181,6 +182,9 @@ function _prune(){
                 if [ "$rc" -eq "0" ]; then
                         mv "${logfile}.running" "${logfile}"
                         iCountPrune+=1
+
+                        # remove last error file if run was ok now
+                        test -f "${logfile}.error" && rm -f "${logfile}.error"
                 else
                         iCountPruneError+=1
                         mv "${logfile}.running" "${logfile}.error"
@@ -206,7 +210,7 @@ function _status(){
         _processes="$( ps -eo command )"
         
         echo "Prune status:"
-        for _dir in $( find ${prune_basedir} -maxdepth 1 -type d | grep -E "$filter")
+        for _dir in $( find ${prune_basedir} -maxdepth 1 -type d | grep -E "$filter" | sort)
         do
             local mybase; mybase=$( basename "${_dir}" )
             local mypw; mypw=$( grep "^${mybase}:" "${cfgfile}" | cut -f2 -d ':')
@@ -218,30 +222,38 @@ function _status(){
             local _flagRunning="."
             local _flagError="."
             local _sLastPrune="?"
+            local _iAge
+            local _iDays
 
             iCountDirs+=1
 
             test -n "$mypw" && _flagPw="Y"
+            grep "\." <<< "$mybase" >/dev/null && _flagPw="."
+
             test -f "$_dir/${sSkipfile}" && _flagArchive="A"
+
             test -f "${logfile}.error" && _flagError="E"
+            test -f "${logfile}.error" && iCountPruneError+=1
+
             grep "restic forget.*${_dir}" <<< "$_processes" | grep -v "grep" | grep . >/dev/null && _flagRunning="R"
 
             if [ -f "${logfile}" ]; then
-                local _iAge; _iAge=$( _getFileAge "${logfile}" )
-                local _iDays; typeset -i _iDays=$(( _iAge/60/60/24 ))
-                _sLastPrune="$_iDays days ago"
+                _iAge=$( _getFileAge "${logfile}" )
+                 typeset -i _iDays=$(( _iAge/60/60/24 ))
+                _sLastPrune="$_iDays d ago"
+                test "$_iDays" -eq "0" && _sLastPrune="today"
             fi
 
             if [ -n "$mypw" ] ||  [ "$_flagArchive" = "A" ] || [ "$bOptAll" -eq "1" ]; then
                 iCountMatch+=1
-                printf "%1s %1s %1s %1s  %-12s %s\n" "$_flagPw"  "$_flagArchive" "$_flagError" "$_flagRunning" "$_sLastPrune" "$_dir"
+                printf "%1s %1s %1s %1s  %-9s %s\n" "$_flagPw"  "$_flagArchive" "$_flagError" "$_flagRunning" "$_sLastPrune" "$_dir"
             fi
 
         done
         if [ "$iCountMatch" -gt "0" ]; then
             echo
-            echo ": : : :  :            :"
-            echo ": : : :  :            +-- repository dir"
+            echo ": : : :  :         :"
+            echo ": : : :  :         +-- repository dir"
             echo ": : : :  +-- last successful prune"
             echo ": : : +-- is it currently running?"
             echo ": : +-- Last prune on error?"
@@ -251,6 +263,7 @@ function _status(){
             echo "INFO: No (matching) Repository was found."
         fi
         echo
+
 }
 # ----------------------------------------------------------------------
 # MAIN
@@ -367,7 +380,7 @@ do
         _prune "${mydir}"
 done
 
-test "$bOptStats" -eq "0" && cat <<ENDSTATS
+cat <<ENDSTATS
 
 Statistics:
 
-- 
GitLab