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