From b71bbb6ff5f0e21790cb5988224fecab46b802c0 Mon Sep 17 00:00:00 2001 From: Matteo Corti Date: Fri, 24 Mar 2023 13:37:44 +0100 Subject: [PATCH] Warn if --today is speficied and the time machine is offline --- ChangeLog | 4 ++++ tmstatus.sh | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b576a4..dc0c42a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2023-03-24 Matteo Corti + + * tmstatus.sh (status): Warn if --today is speficied and the time machine is offline + 2023-03-20 Matteo Corti * tmstatus.sh (status): Number of backups today diff --git a/tmstatus.sh b/tmstatus.sh index e7f7d56..3292e95 100755 --- a/tmstatus.sh +++ b/tmstatus.sh @@ -190,6 +190,8 @@ EOF printf 'Last:\t\toffline\n' printf 'Number:\t\toffline\n' + OFFLINE=1 + fi elif echo "${LISTBACKUPS}" | grep -q 'No backups found for host.'; then @@ -391,25 +393,34 @@ fi if [ -n "${TODAY}" ] ; then - echo + if [ -z "${OFFLINE}" ] ; then + + echo + + TODAYS_DATE="$( date +"%Y-%m-%d" )" + TODAYS_BACKUPS=$( echo "${LISTBACKUPS}" | grep "${TODAYS_DATE}" | sed -e 's/.*\///' -e 's/\.backup//' -e 's/.*\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)$/\1:\2/' ) - TODAYS_DATE="$( date +"%Y-%m-%d" )" - TODAYS_BACKUPS=$( echo "${LISTBACKUPS}" | grep "${TODAYS_DATE}" | sed -e 's/.*\///' -e 's/\.backup//' -e 's/.*\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)$/\1:\2/' ) + # without the grep ':' there is always one line (empty) + NUMBER_OF_TODAYS_BACKUPS=$( echo "${TODAYS_BACKUPS}" | grep -c ':' | sed 's/[ ]//g' ) - # without the grep ':' there is always one line (empty) - NUMBER_OF_TODAYS_BACKUPS=$( echo "${TODAYS_BACKUPS}" | grep -c ':' | sed 's/[ ]//g' ) + if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 0 ] ; then + echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE})" + else + if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 1 ] ; then + echo "${NUMBER_OF_TODAYS_BACKUPS} backup today (${TODAYS_DATE}) at" + else + echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE}) at" + fi + echo "${TODAYS_BACKUPS}" | sed 's/^/ * /' + fi - if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 0 ] ; then - echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE})" - else - if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 1 ] ; then - echo "${NUMBER_OF_TODAYS_BACKUPS} backup today (${TODAYS_DATE}) at" - else - echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE}) at" - fi - echo "${TODAYS_BACKUPS}" | sed 's/^/ * /' - fi + else + + echo + echo "Time Machine offline: cannot list todays' backups" + + fi fi