Skip to content

Instantly share code, notes, and snippets.

@esteigler
Forked from alekseykorzun/gist:9901982
Created March 31, 2014 21:05
Show Gist options
  • Save esteigler/9902236 to your computer and use it in GitHub Desktop.
Save esteigler/9902236 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Author: Aleksey Korzun
# Made Awesome By: Erik
email='[email protected]'
default_max=240
echo "=========================================================================="
echo " Replicator Man v1.0.0 "
echo "=========================================================================="
help() {
echo "Usage: -h 127.0.0.1 [-m 120]" 1>&2;
exit 1;
}
while getopts ":h:m:" o; do
case "${o}" in
h)
h=${OPTARG}
;;
m)
m=${OPTARG}
;;
*)
help
;;
esac
done
shift $((OPTIND-1))
if [ -z "${h}" ]; then
help
fi
if [ -z "${m}" ]; then
m=$default_max
fi
echo
response=`mysql -h $h -e 'SHOW SLAVE STATUS\G' | grep 'Seconds_Behind_Master' | awk -F': ' {' print $2 '}`
if [ "$response" == 'NULL' ] || ! [[ $response =~ ^-?[0-9]+$ ]] || [ "$response" -gt "$m" ]; then
if [ ! -f "/tmp/replicatorman_$h" ]; then
echo "Response: $response" | mail -s "Replication failure on $h" $email
touch "/tmp/replicatorman_$h"
fi
echo 'FAILURE'
exit 1
elif [ -f "/tmp/replicatorman_$h" ]; then
echo "Response: $response" | mail -s "Replication recovery on $h" $email
rm "/tmp/replicatorman_$h"
fi
echo 'SUCCESS'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment