Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
v1.1 - Cleaned up the output to provide a last backed up date. Error …
Browse files Browse the repository at this point in the history
…checking for non-supplied flags.
  • Loading branch information
jedda committed Mar 27, 2013
1 parent 6ecb077 commit a15e024
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion check_osx_launchd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The script takes the above arguments like this:
# ./check_osx_launchd.sh -e com.apple.iCloudHelper,com.apple.NotesMigratorService -c com.apple.servermgrd

preset_exceptions="com.apple.printuitool.agent, com.apple.coreservices.appleid.authentication, com.apple.afpstat-qfa, com.apple.mrt.uiagent, com.apple.printtool.agent, com.apple.accountsd, com.apple.xprotectupdater, com.apple.pfctl"
preset_exceptions="com.apple.printuitool.agent,com.apple.coreservices.appleid.authentication,com.apple.afpstat-qfa,com.apple.mrt.uiagent,com.apple.printtool.agent,com.apple.accountsd,com.apple.xprotectupdater,com.apple.pfctl"
preset_criticals="org.postgresql.postgres"

# don't edit below this line unless you know what to do
Expand Down
54 changes: 36 additions & 18 deletions check_time_machine_currency.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/bin/bash

# Check Time Machine Currency
# by Jedda Wignall
# http://jedda.me
# Check Time Machine Currency
# by Jedda Wignall
# http://jedda.me

# v1.0 - 3 May 2012
# Initial release.
# v1.1 - 3 May 2012
# Cleaned up the output to provide a last backed up date. Error checking for non-supplied flags.

# This script checks the time machine results file on a Mac, and reports if a backup has completed within a number of minutes of the current time.
# Takes two arguments (warning threshold in minutes, critical threshold in minutes):
# ./check_time_machine_currency.sh -w 240 -c 1440
# v1.0 - 3 May 2012
# Initial release.

# Very useful if you are monitoring client production systems, and want to ensure backups are occurring.
# This script checks the time machine results file on a Mac, and reports if a backup has completed within a number of minutes of the current time.
# Takes two arguments (warning threshold in minutes, critical threshold in minutes):
# ./check_time_machine_currency.sh -w 240 -c 1440

# Very useful if you are monitoring client production systems, and want to ensure backups are occurring.

while getopts "d:w:c:" optionName; do
case "$optionName" in
Expand All @@ -20,11 +23,21 @@ c) critMinutes=( $OPTARG );;
esac
done

if [ "$warnMinutes" == "" ]; then
printf "ERROR - You must provide a warning threshold with -w!\n"
exit 3
fi

if [ "$critMinutes" == "" ]; then
printf "ERROR - You must provide a critical threshold with -c!\n"
exit 3
fi

lastBackupDateString=`defaults read /private/var/db/.TimeMachine.Results BACKUP_COMPLETED_DATE`

if echo $lastBackupDateString | grep -q 'does not exist'; then
printf "CRITICAL - Time Machine has not completed a backup on this Mac!\n"
exit 2
if [ "$lastBackupDateString" == "" ]; then
printf "CRITICAL - Time Machine has not completed a backup on this Mac!\n"
exit 2
fi

lastBackupDate=$(date -j -f "%Y-%m-%e %H:%M:%S %z" "$lastBackupDateString" "+%s" )
Expand All @@ -35,12 +48,17 @@ warnSeconds=$(($warnMinutes * 60))
critSeconds=$(($critMinutes * 60))

if [ "$diff" -gt "$critSeconds" ]; then
printf "CRITICAL - Time Machine has not backed up in more than $critMinutes minutes!\n"
exit 2
printf "CRITICAL - Time Machine has not backed up since `date -j -f %s $lastBackupDate` (more than $critMinutes minutes)!\n"
exit 2
elif [ "$diff" -gt "$warnSeconds" ]; then
printf "WARNING - Time Machine has not backed up in more than $warnMinutes minutes!\n"
exit 1
printf "WARNING - Time Machine has not backed up since `date -j -f %s $lastBackupDate` (more than $warnMinutes minutes)!\n"
exit 1
fi

printf "OK - A Time Machine backup has been taken within the last $warnMinutes minutes.\n"
exit 0
if [ "$lastBackupDate" != "" ]; then
printf "OK - A Time Machine backup has been taken within the last $warnMinutes minutes.\n"
exit 0
else
printf "CRITICAL - Could not determine the last backup date for this Mac."
exit 2
fi

0 comments on commit a15e024

Please sign in to comment.