Solved

Linux md5sum script

Posted on 2012-03-13
4
329 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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 …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

770 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