Solved

Linux md5sum script

Posted on 2012-03-13
4
327 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
  • 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 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now