简体   繁体   English

在直到循环中检查字数统计

[英]Check wordcount in until loop

I want to continue my bash script only when my Docker container has 2 mentions of a string in the logs..I tried the following code but can't seem to re-count the variable (using eval), so it stays stuck: 我只想在我的Docker容器在日志中提到2个字符串时才继续执行bash脚本..我尝试了以下代码,但似乎无法重新计算该变量(使用eval),因此它一直卡住了:

number=`docker logs mysql 2>&1 | grep 'mysqld: ready for connections' | wc -l`

until [ "$number" -eq 2 ]; do
    sleep 2
    echo $number
    eval "$number"
done

echo Mysql started and rebooted, continue..

I fixed it like this: 我这样修复:

number=0

until [ "$number" -eq 2 ]; do
    sleep 2
    number=`docker logs mysql 2>&1 | grep 'mysqld: ready for  connections' | wc -l`
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM