小编Abu*_*ane的帖子

使用 awk 获取特定单词

我正在编写一个脚本来使用 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)

mysql command-line bash scripts text-processing

1
推荐指数
1
解决办法
7233
查看次数

标签 统计

bash ×1

command-line ×1

mysql ×1

scripts ×1

text-processing ×1