From: Ralph Ronnquist Date: Thu, 10 Dec 2020 01:29:26 +0000 (+1100) Subject: syntax fix and indentation X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=3d112b32afd8bb785f6c6301293f80501649c7af;p=rrq%2Fnilfs2sss.git syntax fix and indentation --- diff --git a/sss.sh b/sss.sh index fbda5db..0207686 100755 --- a/sss.sh +++ b/sss.sh @@ -37,32 +37,32 @@ function marksnap() { chcp cp $DEV ${MARKYEAR[2]} fi MARK=( "$1" "$2" $3 ) -fi +} { flock 9 -date "+$DEV: %Y-%m-%d %H:%M:%S ---- checking" >&2 -lscp -s $DEV | while read CNO DATE TIME REST ; do - TS="$DATE $TIME" - [ "$CNO" = "CNO" ] && continue - if [[ "$TS" > "$YEARLY" ]] ; then - marksnap YEAR "${DATE:0:4}" $CNO - elif [[ "$TS" > "$MONTHLY" ]] - marksnap MONTH "${DATE:5:2}" $CNO - elif [[ "$TS" > "$WEEKLY" ]] - # For older than most recent week, keep last snapshot each week - marksnap WEEK "$(( 7${DATE:8:2} / 7 - 100 ))" $CNO - elif [[ "$TS" > "$DAILY" ]] - marksnap DAY "${DATE:8:2}" $CNO - elif [[ "$TS" > "$HOURLY" ]] - marksnap HOUR "${DATE:8:2}-${TIME:0:2}" $CNO - else - echo "$CNO $DATE $TIME within last hour" - fi -done | if read X ; then - : # snapshot within last hour -else - date "+$DEV: new snapshot at %Y-%m-%d %H:%M:%S" >&2 - mkcp -s $DEV -fi + date "+$DEV: %Y-%m-%d %H:%M:%S ---- checking" >&2 + lscp -s $DEV | while read CNO DATE TIME REST ; do + TS="$DATE $TIME" + [ "$CNO" = "CNO" ] && continue + if [[ "$TS" > "$YEARLY" ]] ; then + marksnap YEAR "${DATE:0:4}" $CNO + elif [[ "$TS" > "$MONTHLY" ]] + marksnap MONTH "${DATE:5:2}" $CNO + elif [[ "$TS" > "$WEEKLY" ]] + # For older than most recent week, keep last snapshot each week + marksnap WEEK "$(( 7${DATE:8:2} / 7 - 100 ))" $CNO + elif [[ "$TS" > "$DAILY" ]] + marksnap DAY "${DATE:8:2}" $CNO + elif [[ "$TS" > "$HOURLY" ]] + marksnap HOUR "${DATE:8:2}-${TIME:0:2}" $CNO + else + echo "$CNO $DATE $TIME within last hour" + fi + done | if read X ; then + : # snapshot within last hour + else + date "+$DEV: new snapshot at %Y-%m-%d %H:%M:%S" >&2 + mkcp -s $DEV + fi } 9> /var/run/lock/sss.lock