|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Script to compare md5
From couple of hours i try to do a script to compare file MD5. Help would be very appreciated ![]() First i read the md5 stored into a text file (no problem): Code:
md5=`grep -P "^[a-fA-F0-9]{32}" $file`then i want to calculate the checksum and store it : Code:
cmd5=`md5sum licence.gvcl` then problems arrives, i want to compare both: Code:
if [[ $md5 == $cmd5 ]]
then
echo cool md5 is ok
else
echo FAIL MD5
echo $md5
echo $rmd5
fiI'm lost because on screen i see this: Quote:
how to fix it please? |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
It might be a difference in whitespaces. You could try double quoting ("$cmd") the variables. But what's wrong with using
md5sum -c <file_with_md5_sums> ?
|
| The Following User Says Thank You to pludi For This Useful Post: | ||
giova (06-15-2011) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
thank you for your answer, it works fine with quotes (i still very confused with quotes). btw :-c option is refused on my unix box (a qnap NAS). i used to get the file path from a text file but i never succeed to do the checksum after that (tried so many syntaxes): Quote:
Code:
fileLic=`grep -P -o "[^ ]+\.zip(\r)?(\n)?$" ./sums.txt #fileLic contains : ./archives/file1.zip cmd5=`md5sum $fileLic` #or cmd5=md5sum `$fileLic` #or cmd5=$"md5sum $fileLic" always return an "MD5 ERROR ves/file1.zip file doesn't exists" note that prompted path is trunkated, i don't understand why probably an other quote problem... |
|
#4
|
||||
|
||||
|
if is more wasy to do this in perl in my opinion .. there are a lot of modules that can do this.
http://search.cpan.org/~delta/Digest...st/Perl/MD5.pm |
| The Following User Says Thank You to theboogymaster For This Useful Post: | ||
giova (06-15-2011) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
why not use -c option?
Quote:
|
| The Following User Says Thank You to kurumi For This Useful Post: | ||
giova (06-15-2011) | ||
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Altho it's not md5, you can use cmp utility to compare 2 files and test return. If files are different it will return 1, otherwise it will be 0 Code:
root@glitch:/myfiles# cat file* 1 2 1 root@glitch:/myfiles# cmp file1 file2 file1 file2 differ: byte 1, line 1 root@glitch:/myfiles# echo $? 1 root@glitch:/myfiles# cmp file1 file3 root@glitch:/myfiles# echo $? 0 |
| The Following User Says Thank You to Peasant For This Useful Post: | ||
giova (06-15-2011) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare script | noorm | Shell Programming and Scripting | 2 | 01-08-2010 06:00 AM |
| Script to compare lines | init0 | Shell Programming and Scripting | 3 | 01-21-2009 04:13 PM |
| Directory compare script | jwilliams108 | Shell Programming and Scripting | 3 | 02-08-2007 02:10 PM |
| script to compare files | pulse2india | Shell Programming and Scripting | 0 | 10-19-2005 04:32 PM |
|
|