我正在编写一个脚本来使用 bash 脚本检查 mysql 数据库,我想检查表的状态是否不是“OK”,将返回表名并执行更多操作:
检查日志
table1 OK
table2 Some error here
table3 OK
table4 OK
table5 Another error
table6 OK
table7 Broken
table8 A very long error which take a 2 lines
of multiple errors
Run Code Online (Sandbox Code Playgroud)
检查.sh
# check and repair tables
mysqlcheck -u $hostUser -p$hostPasswd --all-databases --check --auto-repair >> check.log
# grep tables status, should return OK
cat check.log | grep 'OK' | awk '{print $2}'| while read status; do
# if any table does not contain OK
if …Run Code Online (Sandbox Code Playgroud)