Little Girl's Mostly Linux Blog

TestZipFiles

Test zip files

This page was last updated on July 18, 2009.

Here are two scripts to test your .zip files. One runs fully in the command line. The other uses kdialog – a GUI program.

Command Line

#!/bin/bash
##################
# TEST ZIP FILES #
##################
echo
# ASKS WHERE ZIP FILES ARE KEPT.
echo "What is the path to the zip files? Example: /home/$USER"
echo
# READS YOUR REPLY.
read zipdirectory
echo
# TELLS YOU THAT IT'S TESTING THE ZIP FILES.
echo "Testing zip files - please wait..."
echo
# PERFORMS THE TEST.
zip -T $zipdirectory/*.zip
# ABORTS IF ZIP FILES ARE NO GOOD.
if [ $? != "0" ] ; then
   echo "The zip test failed - aborting script!"
   exit 1
fi
echo
# LETS YOU KNOW IT'S FINISHED.
echo "Done! Your zip files are good!"

GUI

#!/bin/bash
# THIS FILE WAS CREATED BY FRANK PIRRONE.

# ANNOUNCES SCRIPT ACTION
kdialog --msgbox "This script will test zip files in a directory you choose."

# USER SELECTS DIRECTORY
kdialog --getexistingdirectory * > /tmp/zip_test_dir

# POPUP ANNOUNCES CHECKING - PERSIST 3 SECONDS
kdialog --passivepopup "checking zip files" 3

# ZIP PERFORMS VALIDITY TEST
zip -T `cat /tmp/zip_test_dir`/*.zip

# READ STDERR  AND ABORT IF TEST FAILS
if [ $? != "0" ] ; then
  kdialog --msgbox "The zip test failed - aborting script!"
  exit 1
fi

# OTHERWISE ANNOUNCE SUCCESSFUL CHECK
kdialog --msgbox "Done! Your zip files are good!"

# CLEAN UP TEMP FILE
rm -f /tmp/zip_test_dir


Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: