简体   繁体   English

如何将“tail -f”压缩为压缩(gziped)文件?

[英]How to compress a “tail -f” to a compressed (gziped) file?

I have tried the following, but the resulting file stays at size 0. 我尝试了以下内容,但生成的文件大小为0。

tail -f /logs/localhost.log | gzip -c -9 -f > compressed.gz

localhost.log is very active. localhost.log非常活跃。

Thank you. 谢谢。

logrotate (8)旨在解决此类问题 - 它旋转并压缩日志文件。

You're just not patient enough. 你只是没耐心。 That will work, and it will write to the gzip file. 这将工作,它将写入gzip文件。 It will take a while to accumulate enough input to write the first compressed block. 累积足够的输入以写入第一个压缩块需要一段时间。 Especially if the input is highly compressible, eg the log entries are very similar to each other. 特别是如果输入是高度可压缩的,例如日志条目彼此非常相似。

This has a problem though, in that the gzip file will never be properly terminated, since gzip will never get an end-of-file. 这有一个问题,因为gzip文件永远不会被正确终止,因为gzip永远不会得到文件结束。

You can't do this, because gzip utility doesn't read input line by line, it expects EOF. 你不能这样做,因为gzip实用程序不会逐行读取输入,它需要EOF。 But you can write your on wrapper using any programming language which has zlib implementation. 但是你可以使用任何具有zlib实现的编程语言编写你的包装器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM