I'm trying to write a simple script that takes all the .tar.gz files in a directory and verifies them by using the gzip -tv command:
for zip in *.tar.gz
do
gzip -tv $zip
if [ #? -eq 0 ] ; then #Check return code from tar
echo "File ${zip} verified OK."
exit 0
else
echo "File ${zip} failed to verify. Please check."
exit 1
fi
done
However, when I try to run this, I get the following error:
./integcheck.sh: line 10: syntax error near unexpected token `else'
./integcheck.sh: line 10: ` else'
The script looks right to me, can someone help me out with what I missed? Is it a combination of the for/if/then statements?
Ok, well my idea above worked.. however.. I'm having problems piping the output of the -tv to a log file:
DATE=`date +%m/%d/%y-%H:%M`
echo "$DATE - Starting Integrity Check...." >> /nmltest/cbpnear/data/mrr/scripts/logs/integ.log
echo "Now Testing all MRR archive files for integrity..."
cd /nmltest/cbpnear/data/mrr/mrr
gzip -tv *.tar.gz >> /nmltest/cbpnear/data/mrr/scripts/logs/integ.log
Produces this:
scripts $./integcheck.sh
Now Testing all MRR archive files for integrity...
20080302_1700.tar.gz: OK
20080303_0800.tar.gz: OK
20080308_1700.tar.gz: OK
20080309_0800.tar.gz: OK
I was hoping the >> would pipe the output shown when running the script to the log file...