您现在的位置是:网站首页> 编程资料编程资料
使用shell检查并修复mysql数据库表的脚本_linux shell_
2023-05-26
392人已围观
简介 使用shell检查并修复mysql数据库表的脚本_linux shell_
复制代码 代码如下:
#!/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<
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
您可能感兴趣的文章:
相关内容
- 定时导出mysql本地数据替换远程数据库数据脚本分享_linux shell_
- svn服务器启动和svn服务器重启、停止等操作脚本分享_linux shell_
- 25个好用的Shell脚本常用命令分享_linux shell_
- Shell脚本监控服务器在线状态和邮件报警的方法_linux shell_
- Shell脚本判断IP地址是否合法的方法_linux shell_
- MAC中用Shell脚本批量裁剪各种尺寸的App图标_linux shell_
- 在Shell命令行处理JSON数据的方法_linux shell_
- 用shell脚本在mysql表中批量插入数据的方法_linux shell_
- windows下写的shell脚本在linux执行出错的解决办法_linux shell_
- 用Shell脚本快速搭建Ubuntu下的Nodejs开发环境_linux shell_
