手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >使用shell检查并修复mysql数据库表的脚本
使用shell检查并修复mysql数据库表的脚本
摘要:复制代码代码如下:#!/bin/sh#codebyscpman#功能:检查并修复mysql数据库表#将此脚本加到定时中,脚本执行时,等会读库...

复制代码 代码如下:

#!/bin/sh

#code by scpman

#功能:检查并修复mysql数据库表

#将此脚本加到定时中,脚本执行时,等会读库,列出要修复的所有表,然后计时,开始修复

#修复过程中将损坏的表记录下来,修复完成后,将损坏的表,发邮件通知。

fix_logs='/tmp/fix.log'

user=''

pass=''

check_fix()

{

dblist=`/usr/bin/find /usr/dlm_db/mysql/ -type d | grep -vE "logs|_[1-9]|*bak|test"| sed -e "s#/usr/dlm_db/mysql/##g"`

echo start `date`>$fix_logs

for dbname in $dblist

do

echo $dbname

for tb_name in `/usr/bin/find /usr/dlm_db/mysql/$dbname -type f | awk -F'/' '{print $NF}' | awk -F'.' '{print $1}' | sort -

u`

do

mysql -u$user -p$pass $dbname<<fff>>$fix_logs

check table $tb_name;

repair table $tb_name;

FFF

done

done

echo `date` done>>$fix_logs

}

send_logs()

{

msgip=10.0.7.44

IP=`cat /etc/rc.conf | grep -E "ifconfig_[em1|bce1]" | awk '{print "IP:"$2}'| sed -n 1p `

fix_info=`grep -rE "Error|start|done" $fix_logs`

/usr/bin/logger -p local1.info -h $msgip "the services: $IP mysql_table_fix_info:$fix_info"

}

check_fix

send_logs

【使用shell检查并修复mysql数据库表的脚本】相关文章:

shell对比文件内容脚本分享

bash shell命令行选项与修传入参数处理

把mysql查询结果保存到文件的shell脚本

使用shell脚本分析网站日志统计PV、404、500等数据

并发数据库压力测试的shell脚本代码

编写Bash Shell通过gnuplot绘制系统性能数据图的方法

expect自动检测并重启另外一台服务器上的程序代码

linux批量备份服务器配置文件和目录的脚本

shell脚本自动修复mysql损坏的表

两个备份数据库的shell脚本

精品推荐
分类导航