【问题标题】:terminate linux program when lines repeat endlessly当行无休止地重复时终止linux程序
【发布时间】:2018-11-20 16:37:14
【问题描述】:

我正在处理的一个财务处理程序 cruncher.js 存在难以解决的烦人错误。一个常见问题(其触发输入难以指向并因此避免)导致了这种失败场景:

Downloading account information...
Downloading today orders...
Downloading historical quotes...
Downloading historical quotes...
Downloading historical quotes...
Downloading historical quotes...

一旦 "Downloading history quotes..." 行第三次重复,我就知道它陷入了无限循环并且永远不会退出,也不会跳过它无法正常处理的任何输入情况。

如何将这个 cruncher.js 程序通过管道传送到 |awk,即什么内联 awk 脚本会在其输入中检测到第三个(或第二个,如果更容易)连续重复的行,并在那里终止?

或者也许代替 awk,使用其他常见的 Linux/shell 工具?

【问题讨论】:

  • 换个角度,能不能限制时间?因为这样您就可以准备好构建的工具,例如已经存在的 timeout 100s command
  • 是的,我已经这样做了,超时 6m crappyScript.js 。只是作为防止服务器危机的权宜之计。在被困在这个错误上之前,它已经达到了最大合理的水平,虽然有时合法的运行需要更多的时间。

标签: bash awk pipe infinite-loop


【解决方案1】:

这是一种方法

$ yes | awk -v key='y' '{if($0==key)c++; else c=0} c==3{exit}1' 
y
y

用你重复的值替换键值;和yes 与您的流生成器​​。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多