Mysql主从报警脚本 不指定

kangyang , 2014/07/22 10:52 , SHELL脚本 , 评论(0) , 阅读(2454) , Via 本站原创 | |
#!/bin/sh
cd /tmp/DB_slave__monitor
INIT()
{
IPADD=`ifconfig|grep inet|awk '{print $2}'|sed 's/addr://g'| grep -Ev "^$"`;
Province_name="web";
host_name="server1";
NOWTIME=`date +%Y-%m-%d-%H-%M`;
MAILTO="xxx@xxx.com";
MAIL_SUB="slave is down $NOWTIME !";
tmpfile=mysql_mon.tmp
}

mhead()
{
        echo "" >$tmpfile;
        echo "From :$Province_name $host_name" >>$tmpfile
        echo "State :Report" >>$tmpfile
        echo "ReportBy:$0" >> $tmpfile
        echo "DateTime:$NOWTIME" >> $tmpfile
        echo "Info :$Province_name $host_name Disk Monitor" >> $tmpfile
        echo "IP :$IPADD" >> $tmpfile
        echo "" >>$tmpfile;
}

smail()
{
mail -s "$MAIL_SUB" $MAILTO < $tmpfile -- -f mo@xxx.com

}
INIT;

for x in `mysql -e   "show slave status\G" | grep Running | grep -ie "IO" | awk '{print $2}'`
do

  if [ $x = Yes ]; then
  mhead;
  mysql  -e "show slave status\G" >>$tmpfile;
  smail;
  exit 0;
  fi
done

for y in `mysql -e   "show slave status\G" | grep Running | grep -ie "SQL" | awk '{print $2}'`
do
if [ $y = No ]; then
  mhead;
  mysql -e "show slave status\G" >>$tmpfile;
  smail;
  exit 0;
  fi

done
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]