I have startup script which calls command that produces a lot of output. To preserve space I gzipped its output:#!/bin/bash
my_command 2>&1 | tee >(gzip –stdout > "1.log.gz")
Sadly, when I press Ctrl+C, gzip stops abruptly and compressed log gets damaged. Is there a way to finish command gracefully to get valid gz?
I was unable to reproduce your problem, using "yes" as a substitute for your program — that is
yes 2>&1 | tee >(gzip –stdout > "1.log.gz")
created perfectly valid gz file every time, so wondering if there is something else going on.
However you can isolate the two parts of the command by using named pipes, like this;
# create a named pipe
mknod mypipe p
# start a background job that reads from the pipe
gzip –stdout > "1.log.gz"