Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check if mysql is alive
#!/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
You can’t perform that action at this time.