forked from jedda/OSX-Monitoring-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_ccc_currency.sh
executable file
·60 lines (51 loc) · 2.16 KB
/
check_ccc_currency.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
#!/bin/bash
# Carbon Copy Clone - Check Currency
# by Jedda Wignall
# http://jedda.me
# v1.0 - 2 Jul 2012
# Initial release.
# This script has 2 modes:
# • Can be used as a post-clone script in Carbon Copy Cloner to mark a destination as successful
# • Can be used as a Nagios plugin to check the time of the last successful clone to a destination
# --- In Carbon Copy Cloner (CCC) ---
# Simply set the script as the post-clone shell script (After copying files...) for your scheduled clone.
# More information can be found at my original blog post about this script (http://jedda.me/2012/07/checking-carbon-copy-cloner-nagios/)
# or the documentation on this feature in CCC (http://www.bombich.com/software/docs/CCC/en.lproj/scheduling/performing-actions-before-and-after-the-backup-task.html)
# --- In Nagios ---
# This script checks .ccc_clone_last_completed file on a volume, and reports if a clone has completed successfully within a number of minutes of the current time.
# Takes two arguments (clone destination, warning threshold in minutes):
# ./check_ccc_currency.sh -d '/Volumes/Boot-Clone' -w 1440
destVolume=""
warnMinutes=""
while getopts "d:w:" optionName; do
case "$optionName" in
d) destVolume=("$OPTARG");;
w) warnMinutes=( $OPTARG );;
esac
done
parentProcess=`ps -ocommand= -p $PPID | awk -F/ '{print $NF}' | awk '{print $1}'`
# check to see if we are being called from CCC
if [ "$parentProcess" = "com.bombich.ccc" ]; then
# we are being called by CCC
echo "We are being called by CCC"
if [ $3 -eq 0 ]; then
echo "Clone to $2 was good!"
# clone completed successfully
touch "$2/.ccc_clone_last_completed"
fi
exit 0
else
# we are NOT being called by CCC
if ! [ -f "$destVolume/.ccc_clone_last_completed" ];
then
printf "CRITICAL - $destVolume has never been a successful clone destination!\n"
exit 2
fi
if echo `find "$destVolume/.ccc_clone_last_completed" -mmin +$warnMinutes` | grep -q "$destVolume/.ccc_clone_last_completed"; then
printf "WARNING - A clone has NOT succeeded to $destVolume in more than $warnMinutes minutes\n"
exit 1
else
printf "OK - A clone to $destVolume has succeeded within the last $warnMinutes minutes\n"
exit 0
fi
fi