Use shell + SMS to implement simple MySQL two-way synchronization monitoring

Source: Internet
Author: User
The principle and script are both very simple, that is, whether the Slave_IO_Running and Slave_ SQL _Running values in the synchronization state are both Yes. If not, send a text message to the police.

The principle and script are both very simple, that is, whether the Slave_IO_Running and Slave_ SQL _Running values in the synchronization state are both Yes. If not, send a text message to the police.

The principle and script are both very simple, that is, whether the Slave_IO_Running and Slave_ SQL _Running values in the synchronization state are both Yes. If not, send a text message to the police.

[Root @ mysqlb script] # cat Check_Mysql_Slave_Replication.sh
#! /Bin/sh

./Etc/profile

Db_user = reed
Db_paasswd = reed
LogPath =/root/script/Check_Mysql_Slave_Replication_Log
[! -D $ LogPath] & mkdir-p $ LogPath

Cd $ LogPath

Slave_IO_Running = $ (/usr/local/mysql/bin/mysql-u $ db_user-p $ db_paasswd-e "show slave status \ G" | grep 'slave _ IO_Running '| cut -d ': '-f 2 | cut-d'-f 2)
Slave_ SQL _Running = $ (// usr/local/mysql/bin/mysql-u $ db_user-p $ db_paasswd-e "show slave status \ G" | grep 'slave _ SQL _Running '| cut-d ': '-f 2 | cut-d'-f 2)

FUNC ()
{
Echo "[INFO] $ (date + '% F % t') begin to monitor mysql replication ..."
If ["$ Slave_IO_Running" = "Yes"] & ["$ Slave_ SQL _Running" = "Yes"]; then
Echo "[INFO] $ (date + '% F % t') mysql replication is OK! "
Else
Echo "[ERROR] $ (date + '% F % t') fuck! Mysql24 replication is failed ..."
# Call your own text message script
/Root/script/info_takeok.sh "fuck! Mysql24 replication is failed"
Fi
}
FUNC> Check_Mysql_Slave_Replication $ (date + '% F'). log

Finally, it is written to crontab and detected once a minute.

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.