【问题标题】:tail -f pipe not only the single linetail -f 管道不只是单行
【发布时间】:2014-01-06 19:05:48
【问题描述】:

我想用tail -f 传送日志文件,但只有最后一行。我的命令是

tail -f logfile.log | while read line; do /usr/bin/gammu --sendsms TEXT ****** -text "$line"; done

我看到我可以使用grep --line-buffered,但我的新行不能有任何字符,而且我尝试过的方法不起作用。

【问题讨论】:

  • tail -1f logfile.log?
  • @minitech 感谢您的帮助。但它不起作用。 user@machine:~# tail -1f log.log | while read line; do echo "$line"; doneLine 2#我更新日志文件tail: /var/log/apache2/access.log: file truncatedLine 1Line 2Line 3
  • Tail 会在您截断文件 (cat /dev/null > /file)、删除文件并创建新文件 (rm file; touch file) 或覆盖文件 (cp file2 file) 时抱怨文件被截断。
  • @alvits 谢谢你终于成功了

标签: grep pipe tail


【解决方案1】:

错误表明问题出在其他地方,您没有向我们显示。 下面的测试代码对我来说很好。

tail -1f logfile.log | while read line
do 
   echo /usr/bin/gammu --sendsms TEXT ****** -text "$line"
done

【讨论】:

  • 谢谢。在您的帮助和@alvits 的帮助下,它终于奏效了。我使用echo "hello world" >> lofgile.log 将行附加到我的日志文件中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-10
  • 1970-01-01
  • 2022-01-27
  • 2015-01-08
  • 1970-01-01
  • 2017-05-10
  • 1970-01-01
相关资源
最近更新 更多