I am currently trying to set a script up to monitor whether or not my mySQL databases are having any slave replication errors. I have implemented the following code.
MYSQL_HOST=10.11.12.13
MYSQL_USER=root
MYSQL_PASS=password
EMAILTO=email@email.com
MYSQL_CONN="-h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS}"
MSG=`mysql ${MYSQL_CONN} -e 'show slave status\G' | grep Last_SQL_Error | sed -e 's/ *Last_SQL_Error: //'`
if [ -n "$MSG" ]; then
echo $MSG | mailx -s "MySQL Replication Error" ${EMAILTO}
fi
I am looking to check slave status every so often using a cron table, and if there are any replication errors send an email to the designated address. My current iteration results in empty messages with the heading being sent all the time, rather then only when an error is present.
Any help would be greatly appreciated.