在网上找的并根据实际生产平台修改的监控mysql主从同步并报警的shell脚本,

 #!/bin/sh

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