Created
September 21, 2016 16:16
-
-
Save tperalta82/02ae75c4979fc47c9fe25160b558735a to your computer and use it in GitHub Desktop.
Simple Mysql check/restart
This file contains hidden or 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 | |
MSCONN=$(echo "SHOW GLOBAL STATUS LIKE 'Uptime';" | mysql -pyoursupersecurepasswordthatnotevengodknows) | |
CONSTAT=$? | |
SSTAT=$(service mysqld status) | |
LRET=$? | |
if [ $CONSTAT -ne 0 ] || [ $LRET -ne 0 ]; then | |
subject="Mysql Server Down / Unresponsive"; | |
recipients="[email protected],thisoneisnot@nopecom" | |
message="Mysql Service is down or not responding, restarting service, if it fails to restart or if you receive this message again in 1 minut$ | |
"$(date) | |
/usr/sbin/sendmail "$recipients" << EOF | |
subject:$subject | |
from:$from | |
$message | |
EOF | |
/sbin/service mysqld restart | |
echo "ERR" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should the variables be at the top of the script to be easier to fiddle with without messing the rest of the code?
You are connecting to a local mysql right? Maye you could extend the script to a larger game if you introduce the mysql server IP in the configuration.