mysql監控指令碼

破棉襖發表於2015-05-11
監控mysql服務狀態,如果未執行則通知並重啟,可加入定時任務中
#!/bin/bash
 
result=`/usr/bin/mysqladmin -u root -ppassword ping`
expected='mysqld is alive'
 
if [[ "$result" != "$expected" ]]
then
  echo "mysql Not running"
 
# email subject
SUBJECT="[MYSQL ERROR] - Attempting to restart service"
 
# Email To ?
EMAIL="tongzhi@tom.com"
 
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "$result was received"> $EMAILMESSAGE
echo "when we were expected $expected" >>$EMAILMESSAGE
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
 
sudo /etc/init.d/mysql restart
fi

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29754888/viewspace-1647702/,如需轉載,請註明出處,否則將追究法律責任。

相關文章