==========主从状态监控=================
export LANG=en_US.UTF-8
# monitor master-slave 监控主从同步
hostip="10.136.13.92"
user="root"
pass="test@2015"
message=""
# 监控主从同步状态
slaveStatus=$(mysql -u${user} -p${pass} mysql -e "show global status like ‘slave_running‘ \G" | grep -i "value" | awk ‘{print $2}‘)
if [ "${slaveStatus}" != "ON" ]
then
message="${hostip} slave is off ";
fi
# 监控数据复制延迟
slavePos=$(mysql -u${user} -p${pass} mysql -e "show slave status\G" | grep -i "Master_Log_Pos" )
Read_Master_Log_Pos=$(echo ${slavePos} | awk ‘{print $2}‘)
Exec_Master_Log_Pos=$(echo ${slavePos} | awk ‘{print $4}‘)
delay=$[${Read_Master_Log_Pos} - ${Exec_Master_Log_Pos}]
if [ ${delay} -gt 0 ]
then
message="${message}\n${hostip}主从数据延迟超过${delay}" ;
fi
if [ "${message}" != "" ]
then
echo -e ${message} | mail -s "${hostip}主从复制状态监控" yunwei@anyumedia.com
fi
export LANG=en_US.UTF-8
======备份文件状态监控===================================
# 监控文件是否上传
dt=$(date +%Y%m%d)
myFile03="wsms_secondary_${dt}.tar.gz";
myFile04="wsms_primary_${dt}.tar.gz";
myFile05="anyumedia${dt}.rar";
myFile06=ddung${dt}.tar.gz;
myFile07=DXGame${dt}.tar.gz ;
myFile08=wenzhouren${dt}.tar.gz
fileDesic="未上传的文件:\n" ;
cd /home/yyftp/Backup/DataBackup/
if [ ! -f "$myFile03" ]; then
fileDesic="${fileDesic} 文件${myFile03}未上传\n" ;
fi
if [ ! -f "$myFile04" ]; then
fileDesic="${fileDesic} 文件${myFile04}未上传\n" ;
fi
if [ ! -f "$myFile05" ]; then
fileDesic="${fileDesic} 文件${myFile05}未上传 \n\n\n\n" ;
fi
if [ ! -f "$myFile06" ]; then
fileDesic="${fileDesic} 文件${myFile06}未上传 \n\n\n\n" ;
fi
fileDesic="${fileDesic} 文件大小:\n"
size="${fileDesic} 文件${myFile03}的大小:$(du -sh $myFile03 | awk ‘{print $1}‘)\n"
size="${size}文件${myFile04}的大小:$(du -sh $myFile04 | awk ‘{print $1}‘)\n"
size="${size}文件${myFile05}的大小:$(du -sh $myFile05 | awk ‘{print $1}‘)\n"
size="${size}文件${myFile06}的大小:$(du -sh $myFile06 | awk ‘{print $1}‘)\n"
echo -e "${size}" | mail -s "Backup File status" yunwei@anyumedia.com
export LANG=en_US.UTF-8
=========
解决-bash: mail: command not found的问题
yum -y install mailx jwhois
本文出自 “SQLServer MySQL” 博客,请务必保留此出处http://dwchaoyue.blog.51cto.com/2826417/1650682
原文地址:http://dwchaoyue.blog.51cto.com/2826417/1650682