`
xxd
  • 浏览: 21879 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

MySQL shell(ETPASS): M/S status, Sendmail

阅读更多
This script is actually another slow log detector, but it will also send mail instead of writing logs only.
1. monitor MySQL, if the connection >= 30 then call the sendmail function
---------------------------------------------------------
$ more master_mysql_monitor.sh
#!/bin/sh
flag=30 //more than 30 connections
path=/root/xxd/shell/mysql/monitor
user=username
pass=password
host=IP
logd=`date +%Y%m%d`
logf=$path/logs/mm_run_$logd.log
errf=$path/logs/mm_err_$logd.log
comm="set names utf8;show full processlist;"
date=`date`
shel=`echo $comm | mysql -u$user -p$pass -h$host | awk '{print $0"$"}'`
line=`echo $shel | awk '{zcou=split($0,mcom,"$");for (leij=0;leij
;}' | wc -l`
line=$[line-3]

. $path/include/functions //the sendmail function see 2

if [ $line -gt $flag ];
then
echo "--------------------------------" >> $errf
echo "$date ---- not NULL:$line" >> $errf
echo $shel | awk '{zcou=split($0,mcom,"$");for (leij=0;leij> $errf
echo "--------------------------------" >> $errf
send_mail "m_mysql"
fi

echo "----------------------------------------" >> $logf
echo "$date ---- not NULL:$line" >> $logf
echo $shel | awk '{zcou=split($0,mcom,"$");for (leij=0;leij> $logf
echo "----------------------------------------" >> $logf

$ more slave_mysql_monitor.sh
#!/bin/sh
flag="NULL"
path=/root/xxd/shell/mysql/monitor
user=username
pass=password
host=IP

logd=`date +%Y%m%d`
logf=$path/logs/sm_log_$logd.log
errf=$path/logs/sm_err_$logd.log
comm="set names utf8;show slave status\G;"
date=`date`
line=`echo $comm | mysql -u$user -p$pass -h$host | awk '{if ($1=="Seconds_Behind
_Master:") print $2;}'`

. $path/include/functions

if [[ $line == $flag ]];
then
echo "-----------------------------" >> $errf
echo "$date" >> $errf
echo $comm | mysql -u$user -p$pass -h$host >> $errf
echo "-----------------------------" >> $errf
send_mail "s_mysql"
fi
echo $date >> $logf
2. The sendmail function
--------------------
$ more /root/xxd/monitor/include/functions
#!/bin/sh
function send_mail() {
send=$1
case "$send" in
"m_mysql")
/usr/sbin/sendmail -t
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics