Check if mysql is alive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#debugging | |
#set -x | |
# This script can be used to check if mysql is running when you are using nagios check_by_ssh for difficult to reach hosts | |
# usage: | |
# chmod +x check_mysql.sh | |
# ./check_mysql.sh -h HOSTNAME -u USERNAME -p PASSWORD | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
export PATH | |
while getopts u:p:h: option | |
do | |
case "${option}" | |
in | |
u) USER=${OPTARG};; | |
p) PASS=${OPTARG};; | |
h) HOST=${OPTARG};; | |
esac | |
done | |
MYSQLADMIN=`which mysqladmin` | |
CUT=`which cut` | |
mysql_status=`$MYSQLADMIN -h $HOST -u $USER -p$PASS ping | $CUT -d " " -f 3` | |
case $mysql_status in | |
alive) | |
echo "OK - $mysql_status Mysql is alive, running fine." | |
exit 0 | |
;; | |
*) | |
echo "CRITICAL - $mysql_status Mysql is DOWN." | |
exit 2 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment