The content of this section:
Monitor MySQL master copy of shell script.
Description
Monitoring scripts are tested properly under RHEL5, and other versions of Linux systems are tested on their own, and some of the preparation needed to view this article
Code:
Copy Code code as follows:
#监控mysql Master and slave copying
Cat chk_mysql_rep.sh
#!/bin/bash
#
#script_name: chk_mysql_rep.sh
#check MySQL Replication
#
#ssh root@xen "/usr/local/mysql/bin/mysql-uroot-pdongnan-e ' show slave status\g '-ss" | awk '/running:/ {Print $} '
#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.jb51.net
For HOST in $hosts;d o
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 $} ')
#无法连接的主机, skip this cycle.
Test-z "$key" && continue
#返回结果真
If ["$key" = "Yesyes"];then
#flag真, release the alarm.
If [f "${crondir}/log/$HOST. mysql"];then
#sms
#for Mobile in $MOBILES;d O
#echo "$HOST Replication OK" | /usr/local/bin/gammu--sendsms TEXT "$mobile"-unicode
#done
#mail
For mail in $MAILS;d o
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假, Alarm.
if [!-F "${crondir}/log/$HOST. mysql"];then
#sms www.jb51.net
#for Mobile in $MOBILES;d O
#echo "$HOST replication Error" | /usr/local/bin/gammu--sendsms TEXT "$mobile"-unicode
#done
#mail
For mail in $MAILS;d o
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
#
This article comes from "Dongnan" blog