【发布时间】:2013-05-03 22:19:29
【问题描述】:
我需要一个脚本来运行一系列tail -f 命令并将它们输出到一个文件中。
我需要的是tail -f 运行一段时间来 grep 特定的单词。之所以需要一定时间,是因为其中一些值不会立即显示,因为这是实时日志。
我怎样才能运行这样的东西,比如说 20 秒,输出 grep 命令,然后继续执行下一个命令?
tail -f /example/logs/auditlog | grep test
谢谢
【问题讨论】:
我需要一个脚本来运行一系列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
【讨论】: