首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

shell监控脚本范例—监控mysql主从复制

2013-12-04 
shell监控脚本实例—监控mysql主从复制#Yes?#Yes?#?#variables?ssh/usr/bin/ssh?sh_dir/root/sh/?crondir

shell监控脚本实例—监控mysql主从复制
#Yes?
#Yes?
#?
#variables?
ssh=/usr/bin/ssh?
sh_dir=/root/sh/?
crondir=${sh_dir}crontab?
source ${sh_dir}CONFIG?
hosts="$DB_SLAVE_HOSTS"
#main?
#主循环遍历机器 www.jbxue.com
for HOST in $hosts;do?
log=$crondir/log/mysql_replication_error.log?
key=$($ssh root@$HOST "/usr/local/mysql/bin/mysql -uroot -pdongnan -e 'show slave status\G' -ss" | awk '/Running:/ {printf $2}')?
??? #无法连接的主机,跳过本次循环?
??? test -z "$key" && continue?
??? #返回结果真?
??? if [ "$key" == "YesYes" ];then?
??????? #flag真,解除报警?
??????? if [ -f "${crondir}/log/$HOST.mysql" ];then?
??????????? #sms?
??????????? #for mobile in $MOBILES;do?
??????????????? #echo "$HOST replication ok" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode?
??????????? #done?
??????????? #mail?
??????????? for mail in $MAILS;do?
??????????????? echo "$HOST replication ok" | mail -s "$HOST replication ok" $mail?
??????????? done?
??????????? #flag?
??????????? rm -f "${crondir}/log/$HOST.mysql"?
??????? fi?
??? #返回结果假?
??? else???
check_date=$(date '+ %F %T')?
??????? #flag假,报警?
??????? if [ ! -f "${crondir}/log/$HOST.mysql" ];then?
??????????? #sms www.jbxue.com
??????????? #for mobile in $MOBILES;do?
??????????????? #echo "$HOST replication error" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode?
??????????? #done?
??????????? #mail?
??????????? for mail in $MAILS;do?
??????????????? echo "$HOST replication error" | mail -s "$HOST replication error" $mail?
??????????? done?
??????????? #flag?
??????????? echo "replication error" >"${crondir}/log/$HOST.mysql"?
??????????? #log?
??????????? echo "$check_date $HOST mysql replicaton error" >> $log?
??????? fi?
??? fi?
#?
done?
#?

热点排行