Linux:阻塞直到文件中的字符串匹配(“tail + grep with blocks") [英] Linux: Block until a string is matched in a file ("tail + grep with blocking")
本文介绍了Linux:阻塞直到文件中的字符串匹配(“tail + grep with blocks")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 bash/GNU 工具中是否有某种单行方式来阻止,直到文件中有匹配的字符串?理想情况下,超时.我想避免多行循环.
Is there some one-line way in bash/GNU tools to block until there's a string matched in a file? Ideally, with timeout. I want to avoid multi-line loop.
更新: 似乎我应该强调我希望在匹配字符串时结束进程.
Update: Seems like I should have emphasize that I want the process to end when the string is matched.
推荐答案
感谢两位的回答,但重要的部分是进程阻塞直到找到,然后结束.我发现了这个:
Thanks both for answers, but the important part was that the process blocks until found, then ends. I found this:
grep -q 'PATTERN' <(tail -f file.log)
-q
不是很便携,但我只会使用 Red Hat Enterprise Linux 所以没关系.并超时:
-q
is not much portable, but I will only use Red Hat Enterprise Linux so it's ok.
And with timeout:
timeout 180 grep -q 'PATTERN' <(tail -f file.log)
这篇关于Linux:阻塞直到文件中的字符串匹配(“tail + grep with blocks")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文