lots: shellcheck, streaming stuff, fixes
[distro-setup] / ziva-backup-check
index 5c2ed56d9b749d1b91b256fb5c50f7f579500d30..b646d21c5e8f2f45e4b420df14a333c4b5d97929 100755 (executable)
@@ -10,7 +10,7 @@ pre="${0##*/}:"
 err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
 
 ## begin check on syncthing
-if ! systemctl show --no-page syncthing@ziva | sed -n 's/^MainPID=//p' | egrep '^[0-9]+$' &>/dev/null; then
+if ! systemctl show --no-page syncthing@ziva | sed -n 's/^MainPID=//p' | grep -E '^[0-9]+$' &>/dev/null; then
   err no pid for syncthing@ziva. systemctl status:
   systemctl status syncthing@ziva
 fi
@@ -34,16 +34,16 @@ for prefix in root boot; do
     break
   fi
 
-  read last_snap_sec last_snap < <(
+  read -r last_snap_sec last_snap < <(
     for s in ${snaps[@]}; do
       f=${s##*/}
-      unix_time=$(date -d $(sed -r  's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s)
+      unix_time=$(date -d "$(sed -r  's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#"$vol".})" +%s)
       printf "%s %s\n" $unix_time $s # part of the pipeline
     done | sort -r | head -n 1 ||:
   )
   if [[ ! $last_snap ]]; then
     # should not happen.
-    err "could not find latest snapshot for $svp among ${snaps[*]}"
+    err "could not find latest snapshot for $vol among ${snaps[*]}"
     exit 1
   fi
   if (( last_snap_sec < EPOCHSECONDS - age_limit_sec )); then