2
我在Ubuntu網站上發現了這個整潔的小腳本。該腳本通過將其與ISO(9660)文件的MD5總和進行比較來驗證CD的內容 。我不知道爲什麼腳本在計算md5總和後解析字符串。MD5腳本和grep cmd
CSUM1=$(CHECKSUM "$1" | grep -om1 '^[0-9a-f]*')
我如何驗證傳遞給腳本的cmdline參數是一個真正的MD5哈希(不區分大小寫和十六進制(0-9/A-F))。網上有幾個片段顯示如何驗證MD5散列。如果.md5文件作爲參數傳遞,我想驗證並grep MD5散列,如果散列沒有,則驗證散列。我拿到劇本的計算和比較...
# Compares the checksums of an iso9660 image and a burned disk.
# This script is released into the public domain by it's author.
if [ -n "$BASH" ]
then
shopt -s expand_aliases
fi
if [ -n "$CHECKSUM" ]
then
alias CHECKSUM="$CHECKSUM"
elif which md5deep &> /dev/null
then
alias CHECKSUM='md5deep -e'
else
alias CHECKSUM='md5sum'
fi
if [ -n "$2" ]
then
DISKDEVICE="$2"
else
DISKDEVICE='/dev/cdrom'
fi
CSUM1=$(CHECKSUM "$1" | grep -om1 '^[0-9a-f]*')
# extract cmdline arg
echo 'checksum for input image:' $CSUM1
SIZE=$(stat -c '%s' "$1")
BLOCKS=$(expr $SIZE/2048)
CSUM2=$(dd if="$DISKDEVICE" bs=2048 count=$BLOCKS 2>/dev/null | CHECKSUM | grep -om1 '^[0-9a-f]*')
echo 'checksum for output disk:' $CSUM2
if [ "$CSUM1" = "$CSUM2" ]
then
echo 'verification successful!'
else
echo 'verification failed!'
fi