Skip to content

Instantly share code, notes, and snippets.

@sicksand
Last active January 4, 2018 04:12
Show Gist options
  • Save sicksand/564c420b208b72ece1d60332a5e8f995 to your computer and use it in GitHub Desktop.
Save sicksand/564c420b208b72ece1d60332a5e8f995 to your computer and use it in GitHub Desktop.
Check MySQL Replication Slave is running. If not will email to sysadmin using mailgun
#!/bin/bash
COUNT=`'SHOW SLAVE STATUS\G' | mysql -u root --password=password123 mysql | grep 'Master_Log_Pos' | awk '/Read/{a=$NF} /Exec/{b=$NF} END{print a-b}'`
# echo "count" $COUNT
# check if COUNT value is zero or not zero
if [ $COUNT -gt 0 ]; then
curl -s --user 'api:key-getyourkeyatmailgun' \
https://api.mailgun.net/v3/mg.shafiqmustapa.my/messages \
-F from='MySQL Replication Status <postmaster@mg.shafiqmustapa.my>' \
-F to='Shafiq Mustapa <sicksand@gmail.com>' \
-F cc='Project Manager <pm@zanko.com.my>, Support <support@zanko.com.my>, ' \
-F subject='Please check MySQL Replication Status' \
-F text="Ada beza logs. $COUNT"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment