Created
July 3, 2012 09:06
-
-
Save johanmeiring/3038649 to your computer and use it in GitHub Desktop.
MySQL Replication Status Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# MySQL Replication Status Checker | |
# This script will run the SHOW SLAVE STATUS query on the specified server, and then report it if Last_IO_Errno or Last_SQL_Errno do not equal 0. | |
# Most effective when used as a cron job that runs once every minute. | |
# Version 0.1 | |
# DB Info | |
DBHOST=localhost | |
USERNAME=root | |
PASSWORD=lolololol | |
# Machine's name. Change to something else if you want to. | |
HOSTNAME=`hostname` | |
# Array of email addresses to send emails to. | |
EMAILS=("[email protected]" "[email protected]") | |
# Array of cellphone numbers to send SMS's to. | |
CELLPHONES=("0821112223") | |
# Run query. | |
sql_result=`mysql -h${DBHOST} -u${USERNAME} -p${PASSWORD} -e "SHOW SLAVE STATUS\G" | egrep "(Last_IO_Errno|Last_SQL_Errno)"` | |
# Do checking. | |
if [ `echo $sql_result | awk '{print $2}'` -ne 0 ] || [ `echo $sql_result | awk '{print $4}'` -ne 0 ]; then | |
# Seems to be borked... | |
for email in ${EMAILS[@]} | |
do | |
(echo "Warning: Replication on ${HOSTNAME} seems to be borked. DO SOMETHING!") | mailx -s "Replication Error: ${HOSTNAME}" $email | |
done | |
msg="Replication failure on ${HOSTNAME}. DO SOMETHING!" | |
# URL Encode the SMS | |
#msg="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "${msg}")" | |
msg="$(python -c "import sys; import urllib; print urllib.quote_plus(sys.argv[1]);" "${msg}")" | |
for cell in ${CELLPHONES[@]} | |
do | |
# Use e.g. cUrl to consume some service that sends SMSs. | |
done | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment