Skip to content

Instantly share code, notes, and snippets.

View complex347's full-sized avatar

Xingyu Wu complex347

View GitHub Profile
@complex347
complex347 / MySQL Replication Check
Last active June 8, 2019 00:03 — forked from ssimpson89/MySQL Replication Check
Just a simple Mysql Replication Health Check script I wrote. You can put this in a cron.
#!/bin/bash
### VARIABLES ### \
EMAIL=""
SERVER=""
MYSQL_CHECK=$(/usr/bin/mysql --defaults-file=/etc/mysql/repl_cli_auth.cnf -e "SHOW VARIABLES LIKE '%version%';" || echo 1)
LAST_ERRNO=$(/usr/bin/mysql --defaults-file=/etc/mysql/repl_cli_auth.cnf -e "SHOW SLAVE STATUS\G" | grep "Last_Errno:" | awk '{ print $2 }')
SECONDS_BEHIND_MASTER=$(/usr/bin/mysql --defaults-file=/etc/mysql/repl_cli_auth.cnf -p -e "SHOW SLAVE STATUS\G"| grep "Seconds_Behind_Master:" | awk '{ print $2 }')
IO_IS_RUNNING=$(/usr/bin/mysql --defaults-file=/etc/mysql/repl_cli_auth.cnf -e "SHOW SLAVE STATUS\G" | grep "Slave_IO_Running:" | awk '{ print $2 }')
SQL_IS_RUNNING=$(/usr/bin/mysql --defaults-file=/etc/mysql/repl_cli_auth.cnf -e "SHOW SLAVE STATUS\G" | grep "Slave_SQL_Running:" | awk '{ print $2 }')