下面是编程之家 jb51.cc 通过网络收集整理的代码片段。@H_502_1@
编程之家小编现在分享给大家,也给大家做个参考。@H_502_1@
#!/bin/env bash ############################################################################### # NOTE: # The test system is Ubuntu12.04 # This Scripts all rights reserved deserved by MickeyZZC # Copyright 2013 # ############################################################################### PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH clear username= passwd= MysqLhost="" 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 NO UP" >> /var/log/MysqLstat.log exit 1 fi sleep 10 done if [[ $num -gt 0 ]] ; then MysqLsamchk fi } MysqLsamchk(){ if [[ `which MysqLcheck` == "" ]] ;then MysqLdata=`MysqL -h$MysqLhost -u$username -p$passwd -e"show databases"|grep -vE "MysqL|information_schema|performance_schema|Database"` for i in ${MysqLdata[@]} ; do mytables=`MysqL -h$MysqLhost -u$username -p$passwd -e"use $i;show tables;"|grep -vE "Tables_in_"` for j in ${mytables[@]} ; do table_status=`MysqL -h$MysqLhost -u$username -p$passwd -e"check table $i.$j"|awk 'BEGIN{IFS='\t'}{print $3}'|grep "error"` if [ ! "$table_status" == "" ] ; then MysqL -h$MysqLhost -u$username -p$passwd -e"repair table $i.$j" echo "$(date +%Y%m%d%H%M),$i.$j be repair" >> /var/log/MysqLstat.log fi done done else MysqLcheck --all-databases --auto-repair -u$username -p$passwd |awk '!/OK/ {printf "datetime,%s\n",$1}'|sed "s/datetime/$(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 repaired" /var/log/MysqL.err fi } if [[ $1 = 'check' ]] ; then MysqLsamchk else MysqLlive fi
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。@H_502_1@