繁体   English   中英

在bash脚本中运行tail -f特定时间

[英]Run tail -f for a specific time in bash script

我需要一个脚本来运行一系列tail -f命令并将它们输出到一个文件中。 我需要的是tail -f运行一段时间来grep特定的单词。 这是一段时间的原因是因为其中一些值不会立即显示,因为这是一个实时日志。

我怎么能运行这样的东西让我们说20秒,输出grep命令然后继续下一个命令?

tail -f /example/logs/auditlog | grep test

谢谢

timeout 20 tail -f /example/logs/auditlog | grep test
tail -f /example/logs/auditlog | grep test &
pid=$!
sleep 20
kill $pid

那这个呢:

for (( N=0; $N < 20 ; N++)) ; do tail -f /example/logs/auditlog | grep test ; sleep 1 ; done

编辑:我误解了你的问题,抱歉。 你想要这样的东西:

tail -f /example/logs/auditlog | grep test
sleep 20

暂无
暂无

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

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