Is it possible in bash to finish command piped through gzip gracefully?

Viewed 370

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?

2 Answers
Related