检查tar.gz文件的bash脚本

检查tar.gz文件的bash脚本,bash,centos,Bash,Centos,我有以下脚本,我想在创建cPanel备份(每个网站1.tar.gz文件)后运行该脚本,以检查压缩文件。这并不是要取代手动测试恢复,只是一个额外的检查。问题不是重新返回检查失败的文件列表,而是返回所有文件的列表 #!/bin/bash date=`date +%Y-%m-%d` path="/backups/$date/*.gz" found_errors=0 errors='The following backup files failed the automatic test: \n'

我有以下脚本,我想在创建cPanel备份(每个网站1.tar.gz文件)后运行该脚本,以检查压缩文件。这并不是要取代手动测试恢复,只是一个额外的检查。问题不是重新返回检查失败的文件列表,而是返回所有文件的列表

#!/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 > /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

提前谢谢。

好像有打字错误。我打赌状态检查应该是

#if the exit status was not 0
if [ $? -ne 0 ]; then