我正在尝试使用tail -f
命令监视日志,并且每当我在同一日志的不同行中遇到两个不同的单词时,都需要捕获它们并发送电子邮件通知:
例如:cat example.txt
:
<event> 12345 </event>
<Description> Exception on file transfer for user ABC </Description>
我需要监视用户'ABC'具有'Exception'的事件'12345'。
当我这样做tail -F example.txt | egrep "12345|Exception|ABC"
时
如果看到Grep关键字中的任何一个,则打印命令。相反,仅当遇到grep中的所有关键字时才需要打印。
答案 0 :(得分:1)
尝试
tail -f example.txt | egrep --line-buffered "Exception.*ABC" -B 1 | egrep -v Description
您最终将拥有
<event> 12345 </event>
播放每个参数以查看差异
致谢