I have script to verify a tar file is valid. I'm using cat
in this example, but really I'm validating amazon s3 files streamed in.
#!/bin/bash
cat $1 | tar zxf - > /dev/null
if [ $? -eq 0 ]; then
echo "File is ok ... $1"
else
echo "File is corrupted ... $1"
fi
The trouble is the tar file extracts the files in the .tar.gz. I've tried different variations like tar -C /dev/null
but with no luck. It either fails or it outputs the files to disk.
How do I extract the tar file without it writing the files? A few other posts have recommended tar t
to get the file listing. But I'm not 100% sure just getting file listing will verify the integrity of the files the tar contains.