Little Girl's Mostly Linux Blog

TestBz2Files

Test bz2 files

This page was last updated on July 18, 2009.

Here are two scripts for testing your .bz2 files. One runs fully as a command line script. The other runs kdialog – a GUI program.

Command Line

#!/bin/bash
##################
# TEST BZ2 FILES #
##################
# ASKS WHERE BZ2 FILES ARE KEPT.
echo
echo "What is the path to the bz2 files? Example: /home/$USER"
echo

# READS YOUR REPLY.
read bz2directory
echo

# TELLS YOU THAT IT'S TESTING THE BZ2 FILES.
echo "Testing bz2 files - please wait..."
echo

# PERFORMS THE TEST.
bzip2 -tv $bz2directory/*.bz2

# ABORTS IF BZ2 FILES ARE NO GOOD.
if [ $? != "0" ] ; then
   echo "The bz2 test failed - aborting script!"
   exit 1
fi
echo

# LETS YOU KNOW IT'S FINISHED.
echo "Done! Your bz2 files are good!"

GUI

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

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

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

# POPUP ANNOUNCES CHECKING - PERSIST 2 SECONDS
kdialog --passivepopup "checking bz2 files" 2

# BZIP2 PERFORMS VALIDITY TEST
bzip2 -tv `cat /tmp/bz2_test_dir`/*.bz2

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

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

# CLEAN UP TEMP FILE
rm -f /tmp/bz2_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: