shell監(jiān)控腳本實(shí)例—監(jiān)控mysql主從復(fù)制
更新時(shí)間:2013年11月29日 17:06:50 作者:
分享一例shell腳本,用于監(jiān)測(cè)mysql數(shù)據(jù)庫(kù)的主從復(fù)制,有需要的朋友不妨參考學(xué)習(xí)下
本節(jié)內(nèi)容:
監(jiān)控mysql主從復(fù)制的shell腳本。
說(shuō)明:
監(jiān)控腳本在 rhel5 下測(cè)試正常,其它版本的linux 系統(tǒng)請(qǐng)自行測(cè)試,需要的一些準(zhǔn)備工作可以查看這篇文章
代碼:
復(fù)制代碼 代碼如下:
#監(jiān)控mysql 主從復(fù)制
cat chk_mysql_rep.sh
#!/bin/bash
#
#script_name:chk_mysql_rep.sh
#check mysql replication
#
#ssh root@xen "/usr/local/mysql/bin/mysql -uroot -pdongnan -e 'show slave status\G' -ss" | awk '/Running:/ {print $2}'
#Yes
#Yes
#
#variables
ssh=/usr/bin/ssh
sh_dir=/root/sh/
crondir=${sh_dir}crontab
source ${sh_dir}CONFIG
hosts="$DB_SLAVE_HOSTS"
#main
#主循環(huán)遍歷機(jī)器 www.dbjr.com.cn
for HOST in $hosts;do
log=$crondir/log/mysql_replication_error.log
key=$($ssh root@$HOST "/usr/local/mysql/bin/mysql -uroot -pdongnan -e 'show slave status\G' -ss" | awk '/Running:/ {printf $2}')
#無(wú)法連接的主機(jī),跳過(guò)本次循環(huán)
test -z "$key" && continue
#返回結(jié)果真
if [ "$key" == "YesYes" ];then
#flag真,解除報(bào)警
if [ -f "${crondir}/log/$HOST.mysql" ];then
#sms
#for mobile in $MOBILES;do
#echo "$HOST replication ok" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode
#done
for mail in $MAILS;do
echo "$HOST replication ok" | mail -s "$HOST replication ok" $mail
done
#flag
rm -f "${crondir}/log/$HOST.mysql"
fi
#返回結(jié)果假
else
check_date=$(date '+ %F %T')
#flag假,報(bào)警
if [ ! -f "${crondir}/log/$HOST.mysql" ];then
#sms www.dbjr.com.cn
#for mobile in $MOBILES;do
#echo "$HOST replication error" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode
#done
for mail in $MAILS;do
echo "$HOST replication error" | mail -s "$HOST replication error" $mail
done
#flag
echo "replication error" >"${crondir}/log/$HOST.mysql"
#log
echo "$check_date $HOST mysql replicaton error" >> $log
fi
fi
#
done
#
本文出自 “dongnan” 博客
相關(guān)文章
Linux查看系統(tǒng)時(shí)間的詳細(xì)方法總結(jié)
系統(tǒng)時(shí)間是計(jì)算機(jī)硬件和軟件運(yùn)行的基礎(chǔ),在Linux系統(tǒng)中,查看系統(tǒng)時(shí)間是一項(xiàng)基本任務(wù),本文將從多個(gè)方面介紹Linux查看系統(tǒng)時(shí)間的詳細(xì)方法,需要的朋友可以參考下2023-09-09Shell中實(shí)現(xiàn)整數(shù)自增的幾種方法示例
Linux Shell中寫(xiě)循環(huán)時(shí),常常要用到變量的自增,下面這篇文章主要給大家分享了關(guān)于Shell中實(shí)現(xiàn)整數(shù)變量自增的幾種方法,包括declare -i來(lái)聲明、使用let命令、使用(())以及使用expr命令等等方法,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-08-08獲取站點(diǎn)的各類響應(yīng)時(shí)間(dns解析時(shí)間,響應(yīng)時(shí)間,傳輸時(shí)間)
有時(shí)候?yàn)榱藴y(cè)試網(wǎng)絡(luò)情況,需要返回每個(gè)階段的耗時(shí)時(shí)間,比如DNS解析耗時(shí),建立連接所消耗的時(shí)間,從建立連接到準(zhǔn)備傳輸所使用的時(shí)間,從建立連接到傳輸開(kāi)始所使用的時(shí)間,整個(gè)過(guò)程耗時(shí),下載的數(shù)據(jù)量,下載速度,上傳數(shù)據(jù)量,上傳速度等等2014-03-03