Create corrupted *.tar.gz file ?

Hello. I`m writing a bash script who archive log files and send them to backup server. I need some kind of checking mechanism for *.tar.gz files.

I found something like: gunzip -t file.tar.gz //Not output from it.
And for tar: tar tf file.tar.gz //Only lists archive

1.) I need make a corrupted *.tar.gz file to check if thees commands and make statement if something goes wrong.

2.) How to correctly check *.tar.gz files?

  1. Why?

2

$ gunzip -c file.tar.gt | tar tf -  && echo File is OK || echo File is NOT OK

(or perhaps slightly more practical...)

if (gunzip -c file.tar.gz | tar tf -) 2>/dev/null >&2; then
  echo File OK
else
  echo File NOT OK
fi
1 Like

Because I wanna see output from corrupted gunzip file :slight_smile:

OK, thanks for your examples.

This forum is great, again thanks for answer.

Ah, OK.

There could be many possible causes of a "corrupt" gzip file, which might each give different errors.

Have a look at the output of:

strings $(which gzip)
1 Like