監控mysql主從同步並報警的shell腳本

在網上找的並根據實際生產平臺修改的監控mysql主從同步並報警的shell腳本,mysql

 #!/bin/shsql

cd /tmp/process_monitor
INIT()
{
IPADD=`ifconfig|grep inet|awk '{print $2}'|sed 's/addr://g'| grep -Ev "^$"`;
Province_name="xxx";
host_name="slave";
NOWTIME=`date +%Y-%m-%d-%H-%M`;
MAILTO="xxxxxxx@qq.com";
MAIL_SUB="$Province_name:$host_name log-slave Capacity Report $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 mysql_check@T4GAME
 
}
INIT;
 
for x in `mysql -e   "show slave status\G" | grep Running | grep -ie "IO" | awk '{print $2}'`
do
 
  if [ $x = No ]; 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
相關文章
相關標籤/搜索