i have a simple script
wget -O file.zip www.site.com/asdqwdkjhasd.zip
unzip file.zip
and i call the script
./script.sh
now my problem is if zip file is corrupt then it outputs
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
how can i detect this text in script? If the output of the program contains the string "End-of-central-directory signature not found." then do something.
sometimes the downloaded zip is corrupt so it has to be redownloaded. How can i check if the output is "End-of-central-directory signature not found." and if so redownload i.e execute wget and again unzip. In other words how to loop until download and extract succeeds?
How can i achieve this in bash scripting?
I appreciate any help! Thanks!
UPDATE:
Sorry i have made a slight change to the problem. This is the actual problem i am trying to solve. Thanks for any feedbacks!
unzipis well-written, the error will be reflected in exit status, not just output. Thus, you'll be able to useif unzip "$1"; then echo "unzip succeeded"; else echo "unzip failed"; fi, which is the best-practice approach. Checking for a specific string is fragile: It can fail if a future version of the program changes the message's text, if the user has a different language/locale and thus a different translation table; etc.man rsyncfor an example fo this being done well -- every major failure mode has a distinct, well-documented exit status).