Monday 23 July 2018

Shell script to verify zip archives

Shell script to verify zip archives
This is similar to my little shell one liner to verify tar archives. Exit status of 0 means the archive is good, anything else means there's a problem. Most of the problem archives I encountered had a status of 2, but a few 3's and 9's as well -- see "man unzip" for explanation of status codes. Using a while loop because some of the archive files names have spaces in them, which trips up the for loop:
find . -name "*.zip" | while read f; do unzip -t "$f" &> /dev/null; err="$?"; echo checking "$f"; echo $err "$f" >> zip-check.list; done
Output:
2 ./1-02-cv-00319-RHB-JGS(170).zip
0 ./1-02-cv-00319-RHB-JGS(171).zip
2 ./1-02-cv-00319-RHB-JGS(172).zip
2 ./1-02-cv-00319-RHB-JGS(173).zip
0 ./1-02-cv-00319-RHB-JGS(174).zip
2 ./1-02-cv-00319-RHB-JGS(175).zip
0 ./1-02-cv-00319-RHB-JGS(176).zip
0 ./1-02-cv-00319-RHB-JGS(177).zip
2 ./1-02-cv-00319-RHB-JGS(178).zip
0 ./1-02-cv-00319-RHB-JGS(179).zip

0 comments:

Post a Comment