forked from jedda/OSX-Monitoring-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_crashplan_currency_gnu.sh
executable file
·61 lines (49 loc) · 1.97 KB
/
check_crashplan_currency_gnu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Check Crashplan Currency - GNU
# by Jedda Wignall
# http://jedda.me
# v1.0.1 - 3 May 2012
# Added comments and fixed broken bits.
# v1.0 - 27 Apr 2012
# Initial release.
# This script checks the currency of a CrashPlan backup on Linux. There is a different version for Mac OS X due to differences between date on GNU and BSD.
# Takes three arguments ([-d] cp.properties file in backup destination, [-w] warning threshold in minutes, [-c] critical threshold in minutes):
# ./check_crashplan_currency_gnu.sh -d /media/Backups/52352423423424243/cp.properties -w 240 -c 1440
currentDate=`date "+%s"`
cpDirectory=""
warnMinutes=""
critMinutes=""
while getopts "d:w:c:" optionName; do
case "$optionName" in
d) cpDirectory=("$OPTARG");;
w) warnMinutes=( $OPTARG );;
c) critMinutes=( $OPTARG );;
esac
done
# check to see if the cp.properties file exists
if ! [ -f "$cpDirectory" ];
then
printf "CRITICAL - the CrashPlan backup you pointed to does not exist!\n"
exit 2
fi
lastBackupLine=`grep -n lastCompletedBackupTimestamp "$cpDirectory"`
if [ -z "$lastBackupLine" ]; then
printf "CRITICAL - Could not read the last backup date. Has an initial backup occurred?\n"
exit 2
fi
lastBackupDateString=`echo $lastBackupLine | awk -F lastCompletedBackupTimestamp= '{print $NF}' | sed 's/.\{5\}$//' | sed 's/\\\//g'`
lastBackupDate=$(date -d "$lastBackupDateString" "+%s" )
diff=$(( $currentDate - $lastBackupDate))
warnSeconds=$(($warnMinutes * 60))
critSeconds=$(($critMinutes * 60))
if [ "$diff" -gt "$critSeconds" ]; then
# this cert is has already expired! return critical status.
printf "CRITICAL - $cpDirectory has not been backed up in more than $critMinutes minutes!\n"
exit 2
elif [ "$diff" -gt "$warnSeconds" ]; then
# this cert is expiring within the warning threshold. return warning status.
printf "WARNING - $cpDirectory has not been backed up in more than $warnMinutes minutes!\n"
exit 1
fi
printf "OK - $cpDirectory has been backed up within the last $warnMinutes minutes.\n"
exit 0