?
Solved

Linux md5sum script

Posted on 2012-03-13
4
Medium Priority
?
351 Views
Last Modified: 2012-03-21
Hello,

I would like a script to achieve the following:

(Example locations only)
/tmp/sample-files contains the following files: md5-1, md5-2, md5-3 etc

1. Run the script against the target directory /tmp/sample-files
2. Create a file that contains a list of the files to be checksummed (md5-sum-src)
3. Run the md5sum command against the above file and output the results to another file (md5-sum-results).


Thanks,

Phil
0
Comment
Question by:PhilMacavity
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37713908
Why do you need an intermediate file?

Just run

md5sum /tmp/sample-files/* > md5-sum-results

That's all.

wmp
0
 
LVL 1

Author Comment

by:PhilMacavity
ID: 37713982
Hi Wmp,

Thaks for the comment.

md5sum /tmp/sample-files/* > md5-sum-results would work for my initial plans . Instead of, having to run the md5sum command multiple times against the target directories, i was planning to run it once against a src file containing a list of the files to be checksummed.

Cheers,

Phil.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 750 total points
ID: 37714023
To pull a checksum you will have to access the files (and thus their directories) nonetheless, so what should the file be good for?

Do you expect that the contents of the directories change regularly?

Ok, using an intermediate file would avoid checking new files (which might be intended), but would also try to checksum deleted files, which will lead to errors.

And you don't have to run the md5sum command multiple times:

md5sum /tmp/sample-files-1/* /tmp/sample-files-2/* /tmp/sample-files-3/* > md5-sum-results

Anyway:

find  /tmp/sample-files -type f > md5-sum-src

while read file; do
  md5sum $file >> md5-sum-results
   done < md5-sum-src

wmp
0
 
LVL 1

Author Comment

by:PhilMacavity
ID: 37746424
Hi wmp,

Thanks for the suggestions. These should be enough for me to achieve what i need.

Cheers,

Phil
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month12 days, 8 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question