【发布时间】:2017-07-13 07:28:55
【问题描述】:
在我的 bash 脚本中,我试图监视 /var/log/message 日志文件的输出 - 即使文件旋转(重新创建并重新启动)也继续。我尝试使用tail -f filename,但很快意识到这对文件旋转时没有好处。
因此,使用tail -F filename 或tail -f --retry filename(以及其他一些变体)有很多答案。
但是在我的嵌入式 Linux 上,我使用的是带有轻量级 tail 的 busybox:
tail [OPTIONS] [FILE]...
Print last 10 lines of each FILE to standard output. With more than one
FILE, precede each with a header giving the file name. With no FILE, or
when FILE is -, read standard input.
Options:
-c N[kbm] Output the last N bytes
-n N[kbm] Print last N lines instead of last 10
-f Output data as the file grows
-q Never output headers giving file names
-s SEC Wait SEC seconds between reads with -f
-v Always output headers giving file names
If the first character of N (bytes or lines) is a '+', output begins with
the Nth item from the start of each file, otherwise, print the last N items
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).
所以我不能做通常的tail -F ...,因为那个选项没有实现。上面的文档 sn-p 是最新的busybox版本——我的有点老了。
所以我需要另一种记录 /var/log/messages 的方式,因为文件会以特定大小被覆盖。
我在想一些简单的 bash 行。所以我看到了类似inotifywait的东西,但是busybox没有。我看了这里:
busybox docs 并且有一个 inotifyd,但我的版本没有那个特定的命令。因此,如果有一种聪明的方法可以使用简单的 Linux 命令/watch 和 tail -f 和 cat/less/more 等命令的组合来做到这一点,我正在徘徊......我不太清楚我需要做什么我拥有的有限命令:(
【问题讨论】:
-
@jww 好吧......这是一个微不足道的“离题”电话,不是很有建设性。我将需要它作为我开发的一部分,从技术上讲它是 bash 脚本的一部分。它也是我正在尝试开发的特定代码行(或行) - 所以我认为你不正确,因为 bash 脚本也是代码/开发......想法?
标签: linux bash logging busybox