Validate compressed files

Hi All,

I have zip file that needs to be validated and checked for 5 times with sleep of 60 seconds. Some thing like below

#!/bin/bash
counter=1
while [ "$counter" -le 5 ]
do
      	curl -i -k -X GET `strings tmp.txt |grep Location| cut -f2 -d" "` -H "Authorization: Token $TOKEN" -o $zip_file ## this is where the zip file gets generated
        RC=$?
        if [ "$RC" -eq 0 ]
        then
        echo "Zip file is valid"
        break
        fi
        echo -e "Zip file is not valid for ${counter} time" 
        sleep 60
        counter=$(( counter + 1 ))
        if [ "$counter" -eq 11 ]
        then
        echo -e "After $(( $counter - 1 )) attempts, FAILED!" 
        exit 1
        fi
done

I need to validate the zip file after it gets generated using curl command. Basically needs to validate like below

file $zip_file|grep -v Zip   
   file.zip: data 

The gzip -t command returns a simple exit code to the shell indicating whether the file passed the gzip integrity test or not.

Adding the -v flag will provide a bit more information (but not much).

Thanks Neo, But its not working

gzip -t file.zip

gzip: file.zip: not in gzip format

Sorry, my bad.

Your file is in zip format, not gzip format.

That is why it does not work, isn't that correct?

If correct, then try:

unzip -t

Yup Its working, Can you help me how to apply this in my script like how to check whether its successful or not.

I'll pass the baton of support to someone else; and since you have a way forward, maybe you can try on your own first?

Yup, I tried but its returning 1 for success return and 9 for failure if i give

 $? 

after executing

unzip -t