Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active December 9, 2021 15:34
Show Gist options
  • Save magnetikonline/93fd73878bd88100cf86 to your computer and use it in GitHub Desktop.
Save magnetikonline/93fd73878bd88100cf86 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 \
--batch \
--user root \
--execute "SHOW GLOBAL STATUS LIKE 'Slave_running';" | \
tail --lines 1 | grep --extended-regexp --quiet "^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