title: A bash script to check the tar.gz files
body: <p>I have the following script that I would like to run after a cPanel backup is created (1 .tar.gz file per websites) to check the compressed files. Its not meant to replace manual test restores, but just an extra check. The problem is instead of resturning a list of files that failed the check it returns a list of all the files.</p>
  
  <pre><code>#!/bin/bash
  
  date=`date +%Y-%m-%d`
  path="/backups/$date/*.gz"
  
  found_errors=0
  errors='The following backup files failed the automatic test: \n'
  
  for f in $path
  do
          gunzip -c $f | tar t &gt; /dev/null
  
          #if the exit status was not 0
          if [ $?=0 ]; then
                  found_errors=1
                  errors="$errors\n$f"
                  #echo  $f ": Exit status code is " $?
          fi
  done
  
  #if an error was found
  if [ $found_erros!=0 ]; then
          #email the list of files that could not be extracted/tested
          echo -e $errors | mail -s "Backup Error Check" "admin@example.com"
  fi
  </code></pre>
  
  <p>Thanks in advance.</p>