Skip to content

Instantly share code, notes, and snippets.

@keyurshah
Last active August 8, 2016 17:58
Show Gist options
  • Save keyurshah/4178821 to your computer and use it in GitHub Desktop.
Save keyurshah/4178821 to your computer and use it in GitHub Desktop.
#mysql Detect if a mysql slave is still running and touch slave_running, monit then watches the timestamp on the file
check file slave_running with path /opt/slave_running
if timestamp > 3 minutes then alert
#!/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
@keyurshah
Copy link
Author

added a separate file in /etc/cron.d/slave_running to run the file every minute

* * * * * root /bin/bash /etc/custom_bash_scripts/slave_running.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment