Checking gzip Compressed tar Files

January 22, 2014 | By

I wrote this very simple bash script to check the gzip compressed tar files generated by cPanel’s backup. It attempts to extract each file individually to /dev/null and emails a list of the ones that were not extracted successfully.

Lines 8 through 17 loops through the files in the current directory with a .gz extension and extract each one using gunzip and then tar to /dev/null. If the exit status ($? in bash) is not 0 then gunzip or tar was not successful so the file name is concatenated to the variable error which will contain the body of the email.

Lastly the if statement on line 20 will be executed if one or more of the files was not extracted successfully and will send an email containing the list of corrupted files.

One last thing, the script checks the compressed files on the current directory. If you want to schedule the script to run after a backup process completes, replace the 3rd line with the following two lines and set the path to the location of your backups:

This way the path will be set according to the current date, so make sure it is scheduled to run on the same day as the backup.

If you found this post useful, I’d be very grateful if you’d help it spread by sharing it. Thank you!

Filed in: Linux | Tags: , , ,

Comments are closed.