監控mysql啓動情況并檢測表錯(cuò)誤修複
來(lái)源:創立工(gōng)作(zuò)室 作(zuò≠δ)者:馮軍 發布時(shí)間(jiān):2024-07≤≠∞π-23 11:50:07 閱讀(dú) 1132'♥¥γ 次
#!/bin/env bash
####################↔ #########################################&÷π##################
# NOγ∞♠TE:
# The test syste₽£♠m is Ubuntu12.04
# This Scα₽±ripts all rights reserved deserve★<d by MickeyZZC
# Copyright 2013
#
#≈♦∞#####################################"πδ############################₩β#############
PATH=/bin:/sbin"←:/usr/bin:/usr/sbin:£☆/usr/local/bin:/usr/local/sbin:€♦~/bin
export PATH
clear
u✔φsername=
passwd=
mysqlhקost=""
mysqllive(){
num=0
γ♦¥±
while [[ `pidof mysqld` == "" ]→↔♣] ; do
echo "$(date +%Y%m%d%H¥ ₹%m),MYSQL IS DOWN" >> /var/log/✔↔mysqlstat.log
service mysql start×↔
num=`expr $num + 1`
™• if [[ $num -gt 11 ]] ; then
' ♠ echo "$(date +%Y%m%d%H%m),MYSQL N€$←↔O UP" >> /var/log/mysqlsδ₹£tat.log
exit 1§↔÷×
fi
sleep 10
done
λ₽ if [[ $num -gt 0 ]] ; th'קen
mysqlsamchk
↓¶∏fi
}
mysqlsamchk(){
if [[ `which my♦≤✔sqlcheck` == "" ]] ;t→hen
mysqldata=`mysql -h$mysqlhost -u≈"$username -p$passwd -e"sh♦≤≈ow databases"|grep -♥¶vE "mysql|information_sc☆ ¶hema|performance_schema|Database"`
×↑
for i in ${mysqldata[@]} ; do←βφ→
mytables=`mysql -h$mysqlhost ♣-u$username -p$passwd -e"use $i;show tables;"|grδ£λep -vE "Tables_in_"`
for j in Ω¶${mytables[@]} ; do
π≈φ table_status=`mysql -h$mysqlhost -uσ"©♣$username -p$passwd -e"check ta★↕÷ble $i.$j"|awk 'BEGIN{IFS='\t'}{prinβ®πt $3}'|grep "error"`
if [ ! " $table_status" == "" ] ; then
×★δ mysql -h$mysqlhost -u$username -p$passwd -≠÷₩e"repair table $i.$j"
e♦↕cho "$(date +%Y%m%d%H%M),$i.$j be repair" &am§ ♦p;gt;> /var/log/mysqlstat.logφ®
fi
♣§> done
donλ↑e
else
my£¶€sqlcheck --all-databases --auto-repair -u$usernam€±Ω✘e -p$passwd |awk '!/OK/ {pr↔✔≤intf "datetime,%s\n",$1}'|sed "s/dateti&↕>♦me/$(date +%Y%m%d%H%M)/g" >®≤<;> /var/log/mysqlstat.log
§✘&
# day="$(date +%Y%m%d|cut -b 3-8) $(date +%H)∏× "
# grep "is marked as crashed and should be r<γφ₩epaired" /var/log/mysql.err∞↕
fi
}
if [[ $1 = '≥↔check' ]] ; then
mysqlsamchk
else
∏←®☆ mysqllive
fi
- 上(shàng)一(yī)篇:PHP利用(yòng)正則表達式實現(xiàn)手機(jī)号碼中間(jiān)4位用(£✘♣yòng)星号(*)替換顯示
- 下(xià)一(yī)篇:将惡意登陸IP添加到(dào)防火(huǒ)牆