Shell Monitor script Instance-monitor MySQL master and slave copy _linux shell

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.