Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux编程 > SHELL > » 正文

mysql数据同步完整性监控脚本(基本)

来源: 神父不怕鬼吹灯 分享至:
一个比较坑爹的shell脚本,mysql的主从同步有专门监控脚本,这个在实际情况下基本用不到,不过这是我写的第一个shell脚本,虽然不堪入目,还是纪念一下吧
请各位指正

#!/bin/bash

# Shell script to Monitor MySQL Master server and Slave server working
# When script detects slave mysql server is not working well
# it sends an message.

# This script must be run from Cron Job so that it can monitor mysql server.
# --------------------------------------------------------------------------
# Copyright (C) 2011 yongjun.yin project
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://sfdlut-live-cn.iteye.com/ for more information.
# -------------------------------------------------------------------------

# Master Section
#--------------------------------------------------------------------------
# mysql root/admin username
MUSER="root"
# mysql admin/root password
MPASS="well1410"
# mysql server hostname
MHOST="localhost"
# mysql server dbname
MDB="adn"
#SQL script to query MySQL server
MSCRIPt="../query.sql"
#--------------------------------------------------------------------------

# Slave Section
#--------------------------------------------------------------------------
# mysql root/admin username
SUSER="root"
# mysql admin/root password
SPASS="well1410"
# mysql server hostname
SHOST="localhost"
# mysql server dbname
SDB="adn"
#SQL script to query MySQL server
SSCRIPT="../query.sql"
#--------------------------------------------------------------------------

# start query
sql="use test;select concat('time:',sysdate(),'count=',count(*)) from stu;"

mysql -h $MHOST -u $MUSER -p${MPASS} -e"${sql}" -N >>fileM.out
mysql -h $SHOST -u $SUSER -p${SPASS} -e"${sql}" -N >>fileS.out

#if [ $? -ne 0 ]; then
#echo $result
#fi


i=0
filepath="./fileM.out"
while read LINE
do
        arrM[i]=`echo $LINE | awk -F '=' '{print $2}'`
        #echo  ${arrM[$i]}
        let i++
done<$filepath

i=0
filepath="./fileS.out"
while read LINE
do
        arrS[i]=`echo $LINE | awk -F '=' '{print $2}'`
        let i++
done<$filepath

sum=0
echo ${arrM
  • }
  • echo ${arrS
  • }
  • for((i=0;i<${#arrM
  • };i++));  do
  •         if [ ${arrM[$i]} != ${arrS[$i]} ]; then
                    #echo ${arrM[$i]}
                    #echo ${arrS[$i]}
                    let sum++
            fi
    done

    echo $sum

    Tags:
    分享至:
    最新图文资讯
    1 2 3 4 5 6
    验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
    关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史