Create tmbackupstate.sh

This commit is contained in:
Michael
2023-05-31 17:40:45 +01:00
committed by GitHub
parent 94168e8601
commit 527515d4d3

25
tmbackupstate.sh Normal file
View File

@@ -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