*/10 * * * * /shell/mysql_status.sh > /dev/null 2>&1
#!/bin/bash
port55=`/usr/sbin/lsof -i:3355 | wc -l`
if test $port55 != 0
then
echo "$(date +%F-%T) xxx.xxx.xxx.xxx MySQL status runing!!" >> /shell/mysql_status.log
else
echo "$(date +%F-%T) xxx.xxx.xxx.xxx mysql status stop" >> /shell/mysql_status.log
echo "$(date +%F-%T) xxx.xxx.xxx.xxx mysql status stop" > /shell/mysql_status_err.log
/bin/mail -s "mysql55"
xxxxx@qq.com < /shell/mysql_status_err.log
fi
declare -a sync55
sync55=($(/usr/local/mysql5/bin/mysql -S /tmp/mysql55.sock -uroot
-xxxxx -e 'show slave status\G' | grep "Running" | awk '{print $2}'))
if [ "${sync55[0]}" = "Yes" -a "${sync55[1]}" = "Yes" ]
then
echo "$(date +%F-%T) xxx.xxx.xxx.xxx msyql synchronous security" >> /shell/mysql_status.log
else
echo "$(date +%F-%T) xxx.xxx.xxx.xxx msyql synchronous failure" >> /shell/mysql_status.log
echo "$(date +%F-%T) xxx.xxx.xxx.xxx msyql synchronous failure" > /shell/mysql_status_err.log
/bin/mail -s "mysql55"
xxxxx@qq.com < /shell/mysql_status_err.log
fi
for i in 31 32 33 36;
do
port=`/usr/sbin/lsof -i:33$i | wc -l`
if test $port != 0
then
echo "$(date +%F-%T) 192.168.180.$i mysql status runing!!" >> /shell/mysql_status.log
else
echo "$(date +%F-%T) 192.168.180.$i mysql status stop" >> /shell/mysql_status.log
echo "$(date +%F-%T) 192.168.180.$i mysql status stop" > /shell/mysql_status_err.log
/bin/mail -s "mysql$i"
xxxxxxxxx@qq.com < /shell/mysql_status_err.log
fi
declare -a sync
sync=($(/usr/local/mysql5/bin/mysql -S /tmp/mysql$i.sock -e 'show slave status\G' | grep "Running" | awk '{print $2}'))
if [ "${sync[0]}" = "Yes" -a "${sync[1]}" = "Yes" ]
then
echo "$(date +%F-%T) 192.168.180.$i msyql synchronous security" >> /shell/mysql_status.log
else
echo "$(date +%F-%T) 192.168.180.$i msyql synchronous failure" >> /shell/mysql_status.log
echo "$(date +%F-%T) 192.168.180.$i msyql synchronous failure" > /shell/mysql_status_err.log
/bin/mail -s "mysql$i"
xxxxxx@qq.com < /shell/mysql_status_err.log
fi
done