我需要一个脚本来运行一系列tail -f
命令并将它们输出到一个文件中。
我需要的是tail -f
运行一段时间来查找特定单词。它是一段时间的原因是因为其中一些值不会立即显示,因为这是一个实时日志。
我怎么能运行这样的东西让我们说20秒,输出grep命令然后继续下一个命令?
tail -f /example/logs/auditlog | grep test
由于
答案 0 :(得分:14)
timeout 20 tail -f /example/logs/auditlog | grep test
答案 1 :(得分:4)
tail -f /example/logs/auditlog | grep test &
pid=$!
sleep 20
kill $pid
答案 2 :(得分:0)
这个怎么样:
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