简体   繁体   中英

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

I have tried the following, but the resulting file stays at size 0.

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

localhost.log is very active.

Thank you.

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

You're just not patient enough. That will work, and it will write to the gzip file. 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.

You can't do this, because gzip utility doesn't read input line by line, it expects EOF. But you can write your on wrapper using any programming language which has zlib implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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