Hire me if you like: blake.irvin@gmail.com

Thursday, September 13, 2007

Interactive Shell Script for Verifying MD5 Checksums


#!/bin/bash

echo "Give the path to the file you wish to checksum"

read FILE_TO_CHECK

echo "Give the checksum value you expect for this file"

read EXPECTED_CHECKSUM

echo "$FILE_TO_CHECK should yield checksum $EXPECTED_CHECKSUM" > /tmp/$EXPECTED_CHECKSUM.chksm

GENERATED_CHECKSUM=`md5 $FILE_TO_CHECK | awk '{print $4}'`
CHECKSUM_MATCH=`grep "$GENERATED_CHECKSUM" /tmp/$EXPECTED_CHECKSUM.chksm | wc -l`

if [ $CHECKSUM_MATCH -eq 0 ]; then
echo "$FILE_TO_CHECK did not pass checksum verification"
elif [ $CHECKSUM_MATCH -eq 1 ]; then
echo "$FILE_TO_CHECK passed checksum verification"
fi

rm /tmp/$EXPECTED_CHECKSUM.chksm

exit 0

No comments:

Archive