From 527515d4d3770866acd5ddc25695bb6d3883b047 Mon Sep 17 00:00:00 2001 From: Michael <30936296+mtan93@users.noreply.github.com> Date: Wed, 31 May 2023 17:40:45 +0100 Subject: [PATCH] Create tmbackupstate.sh --- tmbackupstate.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tmbackupstate.sh diff --git a/tmbackupstate.sh b/tmbackupstate.sh new file mode 100644 index 0000000..ead1aef --- /dev/null +++ b/tmbackupstate.sh @@ -0,0 +1,25 @@ +#!/bin/sh +#WARNINGDAYS=14 +#CRITICALDAYS=30 +enabled=$(/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup) + if [ "$enabled" == "1" ];then + datetoday=$(date +%s) + lastBackupTimestamp=`date -j -f "%a %b %d %T %Z %Y" "$(/usr/libexec/PlistBuddy -c "Print Destinations:0:SnapshotDates" /Library/Preferences/com.apple.TimeMachine.plist | tail -n 2 | head -n 1 | awk '{$1=$1};1')" "+%s"` + difference=$(($datetoday-$lastBackupTimestamp)) + TMDAYSSINCE=$(($difference/(3600*24))) + if (( $TMDAYSSINCE > $WARNINGDAYS )); + then + if (( $TMDAYSSINCE > $CRITICALDAYS )); + then + TMBACKUPSTATE="CRITICAL" + else + TMBACKUPSTATE="Warning" + fi; + else + TMBACKUPSTATE="COMPLIANT" + fi; + else + TMBACKUPSTATE="Warning" + fi + +export TMBACKUPSTATE