Skip to content

Instantly share code, notes, and snippets.

@hflamboauto1
Forked from magnetikonline/mysqlslavecheck.sh
Created July 6, 2016 11:01
Show Gist options
  • Save hflamboauto1/adcef9704b085cd2c2858f8e2f1ef574 to your computer and use it in GitHub Desktop.
Save hflamboauto1/adcef9704b085cd2c2858f8e2f1ef574 to your computer and use it in GitHub Desktop.
Example bash script for a PRTG SSH script sensor - this one for MySQL slave to master checks.
#!/bin/bash
# query MySQL for slave replication status
# note: requires [~/.my.cnf] to be present a populated with valid MySQL password
mysql \
-u root \
-Be "SHOW GLOBAL STATUS LIKE 'Slave_running'" | \
tail -n1 | grep -Pqe "^Slave_running\tON$"
if [ $? -eq 0 ]; then
# success
echo "0:100:Slave connected to master"
else
# failure
echo "2:0:Slave disconnected from master"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment