小编ram*_*ram的帖子

while 循环中的“tail -f | grep 错误”不起作用

下面的命令没有给出任何结果。我想grep从文件中提取错误行并插入到表中。

不起作用的命令:

tail -f logfile.log | grep  ERROR|while read msg; do psql -d testdb -c insert into t values('$msg'); done
Run Code Online (Sandbox Code Playgroud)

但是如果我grep ERROR从命令中删除代码,它会按预期工作。我不确定发生了什么?

运行正常的命令:

tail -f logfile.log|while read msg; do psql -d testdb -c insert into t values('$msg'); done
Run Code Online (Sandbox Code Playgroud)

您可以假设文件中有以下数据:

ERROR
sql committed
ERROR
ERROR
error
...
Run Code Online (Sandbox Code Playgroud)

grep scripting pipe tail

3
推荐指数
1
解决办法
3985
查看次数

标签 统计

grep ×1

pipe ×1

scripting ×1

tail ×1