Skip to content

Instantly share code, notes, and snippets.

@xitara
xitara / MySQL Replication Check
Last active August 14, 2018 12:08 — 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=""
BCC=""
LOGIN="-u username -pchangeme"
SERVER=$(hostname)
MYSQL_CHECK=$(mysql $LOGIN -e "SHOW VARIABLES LIKE '%version%';" || echo 1)
LAST_ERRNO=$(/usr/bin/mysql $LOGIN -e "SHOW SLAVE STATUS\G" | grep "Last_Errno" | awk '{ print $2 }')
SECONDS_BEHIND_MASTER=$(/usr/bin/mysql $LOGIN -e "SHOW SLAVE STATUS\G"| grep "Seconds_Behind_Master" | awk '{ print $2 }')