J'ai trouvé ce petit script sur le site Web d'Ubuntu. Le script vérifie le contenu du CD en le comparant à une somme MD5 d'un fichier iso (9660). Je ne comprends pas pourquoi le script analyse la chaîne après le calcul de la somme md5.MD5 Script et grep cmd
CSUM1=$(CHECKSUM "$1" | grep -om1 '^[0-9a-f]*')
Comment puis-je vérifier l'argument cmdline passé au script est un véritable md5 (insensible à la casse et de six pans (0-9/a-f)). Il y a plusieurs extraits en ligne montrant comment vérifier les hachages md5. Je veux vérifier et grep le hachage MD5 si un fichier .md5 est passé en argument ou vérifier le hachage si ce n'est pas le cas. Je suis le script pour calculer et comparer ...
# 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