屏幕导致“尾巴-F | grep“来回显不匹配的行

这是Ubuntu(3.13.0-29-generic#53),试图做一个简单的bash脚本来监视匹配行的日志文件。

如果我执行以下操作,除了预期的匹配外,bash shell中不会有输出:

tail -F server.log | grep – 行缓冲“单词”| tee -a wordwatch.log

但是,如果我尝试在屏幕上做同样的事情,会话被垃圾邮件与监视的日志文件中的不匹配的数据。 显然,它显示了从观看的日志文件中的一切。 这个垃圾邮件不会出现在输出日志文件中。

屏幕-S“wordwatch”尾部-F server.log | grep – 行缓冲“单词”| tee -a wordwatch.log

我在做什么错了,我该如何停止监视日志垃圾邮件的屏幕会话?

当你以这种方式启动pipe道时:

screen -S "wordwatch" tail -F server.log | grep --line-buffered "word" | tee -a wordwatch.log 

那么只有tail -F server.log是在screen内启动的,其余的都连接到screen ,而不是tail

因此,你应该调用你已经工作的bash脚本:

 screen -S "wordwatch" myworkingscript.sh 

另一种方法是明确启动shell并将所有行传递给它:

 screen -S "wordwatch" bash -c 'tail -F server.log | grep --line-buffered "word" | tee -a wordwatch.log' 

另外一个好的方法来观看屏幕日志 – 是特殊的configuration:

 #### logger.screenrc sessionname logger hardstatus alwaysignore split split screen -t "Log One" 1 sh -c 'tail -F /a/b/c | egrep "xxxx" | tee -a ' focus screen -t "Log Two" 2 /home/somescript.sh focus screen -t "Messages" 3 /home/otherscript.sh focus #### 

screen应该像这样调用:

 # screen -c /home/logger.screenrc 

要退出,只需按<CTRL-A><CTRL-\>并确认。