[英]Linux tail on rotating log file using busybox
在我的bash腳本中,我試圖監視/ var / log / message日志文件中的內容-即使文件旋轉(重新創建並再次啟動)也要繼續。 我嘗試使用tail -f filename
但很快意識到這對於文件旋轉時沒有好處。
因此,使用tail -F filename
或tail -f --retry filename
(以及其他一些變體)有很多答案。
但是在我的嵌入式Linux上,我使用的是busybox,它的輕量級版本為tail:
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 ...
因為該選項未實現。 上面的文檔片段是最新的busybox版本-而我的版本稍舊。
因此,我需要另一種記錄/ var / log / messages的方法,因為該文件會被覆蓋為一定大小。
我在想一些簡單的bash行。 因此,我看到了諸如inotifywait之類的東西,但是busybox沒有。 我在這里看:
busybox文檔,並且有inotifyd,但是我的版本沒有該特定命令。 因此,我想知道是否有一種巧妙的方法可以通過簡單的Linux命令/諸如watch
and tail -f
和cat/less/more
等命令組合來完成此操作……我不太清楚我該怎么做我擁有的有限命令:(
日志如何旋轉? 您是否正在使用logrotate
實用程序? 如果是,是否嘗試將行添加到配置文件中的postrotate
部分?
從男人logrotate
postrotate / endscript在旋轉日志文件后,將執行postrotate和endscript之間的行(兩者都必須自己顯示在行上)。 這些偽指令只能出現在日志文件定義中。 另請參見預旋轉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.