<分区>
我必须阅读日志,直到收到“Server Startup
”。
当我得到字符串“startup
”时,我必须退出 tail
命令并继续执行其余的脚本操作。
现在语法是:
cd /opt/path/path/path
LOG_FILE=$(ls -ltr | tail -1 |awk '{print $9}')
tail -f $LOG_FILE
提前致谢
<分区>
我必须阅读日志,直到收到“Server Startup
”。
当我得到字符串“startup
”时,我必须退出 tail
命令并继续执行其余的脚本操作。
现在语法是:
cd /opt/path/path/path
LOG_FILE=$(ls -ltr | tail -1 |awk '{print $9}')
tail -f $LOG_FILE
提前致谢
最佳答案
stdbuf -oL tail -f log.file | stdbuf -iL awk '/startup/ {print "Match found";exit}'
这将检查字符串 startup
,当找到时,它会打印“Match found”,然后退出日志监控。 stdbuf
提供缓冲到 tail 和 awk 的行。
关于linux - BASH Linux 退出读取日志直到特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39571068/