检测 MySQL 是否宕掉,如果宕掉则启动

2015-11-24 0 222
检测 MySQL 是否宕掉,如果宕掉则启动
#!/bin/bash

result=`/usr/bin/mysqladmin ping`
expected='mysqld is alive'

if [[ "$result" != "$expected" ]]
then
echo "It's dead - restart mysql"

# email subject
SUBJECT="[MYSQL ERROR] - Attempting to restart service"

# Email To ?
EMAIL="info@endyourif.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

遇见资源网 shell 检测 MySQL 是否宕掉,如果宕掉则启动 http://www.ox520.com/17266.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务