#!/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
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