public
Last active

Detect if a mysql slave is still running and touch slave_running, monit then watches the timestamp on the file

  • Download Gist
slave_running
1 2
check file slave_running with path /opt/slave_running
if timestamp > 3 minutes then alert
slave_running.sh
Shell
1 2 3 4 5 6 7 8
#!/bin/bash
MYSQL=`mysql --defaults-file=/etc/mysql/debian.cnf -e "SHOW SLAVE STATUS \G"`
IO=`echo "$MYSQL" | grep 'Slave_IO_Running:' | awk '{print $2}'`
SQL=`echo "$MYSQL" | grep 'Slave_SQL_Running:' | awk '{print $2}'`
if [ "Yes" == "$IO" ] && [ "Yes" == "$SQL" ]; then
touch /opt/slave_running
fi
exit

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.