I'm working on a embedded system and due to persistent memory restrictions, I need to compress a log file "on the fly".
My objective is to have a one liner inside a script, which would look like this:
(myLaunchScript.sh 2>&1 | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' | busybox gzip -c > /mnt/persistenMem/log_app.log.gz 2>&1 )&
- awk is a helper to add datetime to traces. This reduces overhead in application printf.
The problem is that this implementation loses output if the system is powered off unespectedly, as gzip has an internal buffer. That internal buffer may differ depending on which options busybox was compiled.
Is there any compression tool that implements an unbuffered logic?
Or a line by line compression? Is it possible?