[英]Run tail -f for a specific time in bash script
I need a script that will run a series of tail -f
commands and output them into a file. 我需要一个脚本来运行一系列
tail -f
命令并将它们输出到一个文件中。 What I need is for tail -f
to run for a certain amount of time to grep specific words. 我需要的是
tail -f
运行一段时间来grep特定的单词。 The reason it's a certain amount of time is because some of these values don't show up right away as this is a live log. 这是一段时间的原因是因为其中一些值不会立即显示,因为这是一个实时日志。
How can I run something like this for let's say 20 seconds, output the grep command and then continue on to the next command? 我怎么能运行这样的东西让我们说20秒,输出grep命令然后继续下一个命令?
tail -f /example/logs/auditlog | grep test
Thanks 谢谢
timeout 20 tail -f /example/logs/auditlog | grep test
tail -f /example/logs/auditlog | grep test &
pid=$!
sleep 20
kill $pid
What about this: 那这个呢:
for (( N=0; $N < 20 ; N++)) ; do tail -f /example/logs/auditlog | grep test ; sleep 1 ; done
EDIT: I misread your question, sorry. 编辑:我误解了你的问题,抱歉。 You want something like this:
你想要这样的东西:
tail -f /example/logs/auditlog | grep test
sleep 20
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.