linux - 跟踪日志直到达到特定时间阈值

标签 linux shell ksh sh

我正在跟踪这样的日志:

while [[ ! -n "${ready}" ]]; do
    start_info=`grep "Ready" $LOG_FILE`
    sleep 10
done

如果日志文件中没有“Ready”,这将永远持续下去,我怎样才能让它运行200秒?就像某种时间阈值。

谢谢

最佳答案

这可以避免重复 grep 整个文件:

start=$SECONDS
limit=200
while read -r line
do
    if [[ $line =~ $ready ]]
    then
        start_info=$line
        break
    fi
    if (( $SECONDS >= start + limit ))
    then
        break
    fi
done < "$LOG_FILE"

关于linux - 跟踪日志直到达到特定时间阈值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4526627/

相关文章:

java - 将参数传递给脚本 - 参数是位于上一个目录的配置文件

bash - 当今最好的(可移植和可维护的)Shell 脚本语言是什么?

linux - 使用 awk 反转字段

linux - 尝试在 Scientific Linux 6.2 版上安装 oracle

bash - 如何在 bash 中的 grep 中指定命令行参数?

linux - 如何将 ksh -x 的输出重定向到 unix 中的文件

linux - 使用 7zip 解压文件后如何重命名这些文件并保存

C Linux下串口读取数据失败

linux - Errno 14 PYCURL ERROR 22 请求的URL返回错误403 Forbidden

shell - 将 shell 文件转换为 Windows 批处理文件