Script to compare md5

Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Script to compare md5
# 1  
Old 03-27-2011
Script to compare md5

From couple of hours i try to do a script to compare file MD5.
Help would be very appreciated Smilie

First i read the md5 stored into a text file (no problem):
 md5=`grep -P "^[a-fA-F0-9]{32}" $file`

then i want to calculate the checksum and store it :
cmd5=`md5sum licence.gvcl`

then problems arrives, i want to compare both:
 if [[ $md5 == $cmd5 ]]
               echo cool md5 is ok
              echo FAIL MD5
              echo $md5
              echo $rmd5

I'm lost because on screen i see this:
ab4f63f9ac65152575886860dde480a1 myfile.txt
ab4f63f9ac65152575886860dde480a1 myfile.txt
looks like md5 or cmd5 is not a string?
how to fix it please?
# 2  
Old 03-28-2011
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>?
This User Gave Thanks to pludi For This Post:
# 3  
Old 03-29-2011
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):
where sums.txt contains lines like:
658f410acab9a2d08514af4957cf7422 ./archives/
   fileLic=`grep -P -o "[^ ]+\.zip(\r)?(\n)?$" ./sums.txt
#fileLic contains : ./archives/
cmd5=`md5sum $fileLic`
#or cmd5=md5sum `$fileLic`
#or cmd5=$"md5sum $fileLic"

always return an "MD5 ERROR ves/ file doesn't exists"
note that prompted path is trunkated, i don't understand why probably an other quote problem...
# 4  
Old 03-29-2011
if is more wasy to do this in perl in my opinion .. there are a lot of modules that can do this.
This User Gave Thanks to theboogymaster For This Post:
# 5  
Old 03-29-2011
why not use -c option?
# md5sum --help
Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.

-b, --binary read in binary mode
-c, --check read MD5 sums from the FILEs and check them
This User Gave Thanks to kurumi For This Post:
# 6  
Old 04-11-2011
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
root@glitch:/myfiles# cat file*
root@glitch:/myfiles# cmp file1 file2
file1 file2 differ: byte 1, line 1
root@glitch:/myfiles# echo $?
root@glitch:/myfiles# cmp file1 file3
root@glitch:/myfiles# echo $?

This User Gave Thanks to Peasant For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to reverse the b64 format(encoded b64(b64(md5($pass)))) into md5 hash format?

I have about 1500 rows (encoded b64(b64(md5($pass))) algorythm) in a file. I would like reverse the b64 into md5 hash format. How could I do that from command line? So I need only the correct md5 hash formats. These row format: 4G5qc2WQzGES6QkWAUgl5w P9tKxonBOg3ymr8vOBLnDA... (1 Reply)
Discussion started by: freeroute
1 Replies

2. Shell Programming and Scripting

scp script with MD5

I have more than one file in my directory & I want to SCP them all with MD5 verification of local & remote file, Problem is that the script gets stop after scp one file. Below is the code. #!/usr/bin/bash cd /application/datafolder/my/ ls > my_file_list.txt while read fname do ... (7 Replies)
Discussion started by: m_raheelahmed
7 Replies

3. Solaris

md5 checksum what does it do

Hello good people, I came across md5 checksum. Can anyone please explain to me what it does and if possible an example of how to use it? Thank you very much (1 Reply)
Discussion started by: cjashu
1 Replies

4. Shell Programming and Scripting

Help with MD5 script

Hi, I tried to write script, which would be able to generate MD5 sums into txt file.. But It won't work.. (I've been trying to fix that over 4 hours, but nothing helps) Here it is #!/bin/bash FILE="nothing1" POST="nothing2" I=1 while do FILE=`ls -ltR | grep "^-" | tr -s "... (1 Reply)
Discussion started by: TheBarnacle
1 Replies

5. Shell Programming and Scripting

Create md5 sums and archive the resulting md5 files

Hello everyone, I am looking to basically creating md5sum files for all iso files in a directory and archive the resulting md5 files into a single archive in that very same directory. I worked out a clumsy solution such as: #find files for which md5sum are to be created and store the... (1 Reply)
Discussion started by: SurfTranquille
1 Replies

6. Shell Programming and Scripting

Need to create a simple script using MD5, SSH...

Hi all, I am brand new to these forums and I am a brand new UNIX Administartor. Don't know any scripting yet :wall:, and would like to learn as my boss is slowly letting me understand everything about being a Sys/*Nix Admin. He created this script which I am trying to replicate because I lost it... (54 Replies)
Discussion started by: zixzix01
54 Replies

7. Shell Programming and Scripting

[Bash] MD5 Checks with Script.

Hi. I'm triyng to make a Bash Script that checks (recursively) the MD5 from all the files in a certain directory and compare them against some other check that should be already done and saved in a file. I've reached to the point where i have the MD5 from the file and the MD5 that the script... (1 Reply)
Discussion started by: BiFo
1 Replies

8. Shell Programming and Scripting

Help with md5 in PERL

I am a newbie in programming in Perl. My problem is that this unix command is embedded in Perl but it gives an empty output. Here's the code: $temp = `md5 "../Directory String/..." | awk {'print $NF'} > "../Directory/file.txt"`; The output file should contain the md5 hash value of the... (2 Replies)
Discussion started by: ianebaj
2 Replies

9. Linux

Need Help: MD5

I am trying to compare two identical files by using md5 command, but cant get the right command parameters Please help me with any examples. All I want is to know how to compare two identical files which are residing on two different machines in my local network, for example: Host_A -... (6 Replies)
Discussion started by: greenja
6 Replies

10. Shell Programming and Scripting


Does anyone know a scipt that includes MD5. I need to run a script that includes MD5 encryption. Thanks (1 Reply)
Discussion started by: duncang3
1 Replies
Login or Register to Ask a Question

Featured Tech Videos