This is a discussion on md5sum syntax question within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Hi, I want to integrate an md5sum check in a script for checking file integrity, but I can't get ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I want to integrate an md5sum check in a script for checking file integrity, but I can't get the syntax right. man md5sum is rather laconic on the subject, and info md5sum is the same as man What I attempt to do: 1) I have a downloaded source tarball, so I want to generate an md5 file from it. md5sum source.tar.bz2 > source.tar.bz2.md5 .... I'm not sure if the resulting .md5 file should have a special name, like CHECKSUMS.md5 or similar. 2) Check the file against the existing .md5 that I just generated: md5sum -c source.tar.bz2 .... but here, I get the message that there's no file to check against. Eventually, this will be integrated into a script that downloads source tarballs and checks them for integrity. Any suggestions? Niki Kovacs |
| |||
| Niki Kovacs wrote: > Hi, > > I want to integrate an md5sum check in a script for checking file > integrity, but I can't get the syntax right. man md5sum is rather > laconic on the subject, and info md5sum is the same as man > > What I attempt to do: > > 1) I have a downloaded source tarball, so I want to generate an md5 file > from it. > > md5sum source.tar.bz2 > source.tar.bz2.md5 > > ... I'm not sure if the resulting .md5 file should have a special name, > like CHECKSUMS.md5 or similar. > > 2) Check the file against the existing .md5 that I just generated: > > md5sum -c source.tar.bz2 > > ... but here, I get the message that there's no file to check against. > > Eventually, this will be integrated into a script that downloads source > tarballs and checks them for integrity. > > Any suggestions? md5sum -c source.tar.bz2.md5 md5sum -c < source.tar.bz2.md5 Regards Kees. -- Kees Theunissen. |
| |||
| Niki Kovacs wrote : > 2) Check the file against the existing .md5 that I just generated: You'll have to use the checksum file you just created this way: md5sum -c < source.tar.bz2.md5 And no, the checksum file doesn't have to have any special name, you can call it whatever you want. -- Thomas O. This area is designed to become quite warm during normal operation. |
| |||
| Jérôme PRIOR wrote: >> md5sum -c source.tar.bz2.md5 > > to verify the source.tar.bz2 sum To be more precise: to verify all the files whose checksums are included in source.tar.bz2.md5. In this case there is only one checksum in the file. What needs to be clear is that the files to be checked are mentioned in the checksum-file. It doesn't depend in any way on the name of that checksum-file. You might want to have a look at the different CHECKSUMS.md5 files in the Slackware distribution. > >> md5sum -c < source.tar.bz2.md5 > > and that for ? Just another way to do the same. If you don't specify a checksum-file then 'md5sum -c' will use standard input. Kees. -- Kees Theunissen |
| |||
| Niki Kovacs <mickey@mouse.com> writes: > Hi, > > I want to integrate an md5sum check in a script for checking file > integrity, but I can't get the syntax right. man md5sum is rather > laconic on the subject, and info md5sum is the same as man > > What I attempt to do: > > 1) I have a downloaded source tarball, so I want to generate an md5 > file from it. > > md5sum source.tar.bz2 > source.tar.bz2.md5 > > ... I'm not sure if the resulting .md5 file should have a special > name, like CHECKSUMS.md5 or similar. It's common to use <file>.md5 if the file contains MD5 check sum of <file> and nothing else and CHECKSUMS.md5 (or simply CHECKSUMS) if the file contains check sums of all files in a given directory (and optionally sub-directories). > 2) Check the file against the existing .md5 that I just generated: > > md5sum -c source.tar.bz2 You need: md5sum -c source.tar.bz2.md5 or: md5sum -c CHECKSUMS.md5 You can also make it read check sums from standard input, so that you can put MD5 check sums into a shell script. -- Best regards, _ _ .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo-- |
| |||
| On 2006-11-04, Niki Kovacs <mickey@mouse.com> wrote: > md5sum -c source.tar.bz2 > > ... but here, I get the message that there's no file to check against. The correct usage is: md5sum -c foo.md5 .....with both files being in the same directory. Correct output will look like this: foo: OK As pointed out in other replies, md5sum -c < foo.md5 will also work, but the < is redundent and therefor unnecessary. You are correct in using: md5sum foo > foo.md5 .....to create a checksum file, but often only the hash (md5 number) is provided or already given. To make a proper .md5 file from this number, create the file with name foo.md5 and contents of: hash foo Note there are two spaces --no more, no less-- between the hash and file name. This is the proper syntax and will provide the correct response with the -c option. nb |
| |||
| notbob wrote: > > Note there are two spaces --no more, no less-- between the hash and > file name. This is the proper syntax and will provide the correct > response with the -c option. Are you sure about that format: two spaces --no more, no less-- ? Have a look at this: kees@lankhmar:~$ md5sum /etc/fstab d0186e8995c2a6a1d7e7945041bb10e9 /etc/fstab kees@lankhmar:~$ md5sum -t /etc/fstab d0186e8995c2a6a1d7e7945041bb10e9 /etc/fstab kees@lankhmar:~$ md5sum -b /etc/fstab d0186e8995c2a6a1d7e7945041bb10e9 */etc/fstab Note the "*" in the last line instead of a " ". The build in help says: kees@lankhmar:~$ 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 -t, --text read in text mode (default) The following two options are useful only when verifying checksums: --status don't output anything, status code shows success -w, --warn warn about improperly formatted checksum lines --help display this help and exit --version output version information and exit The sums are computed as described in RFC 1321. When checking, the input should be a former output of this program. The default mode is to printa line with checksum, a character indicating type (`*' for binary, ` ' for text), and name for each FILE. Report bugs to <bug-coreutils@gnu.org>. There _is_ certainly an other format, but I'm wondering why. All tests I did result in the same hash, not depending on the use of -b or -t or no option. Regards, Kees. -- Kees Theunissen. |
| |||
| On 2006-11-04, Kees Theunissen <theuniss@rijnh.nl> wrote: > Are you sure about that format: two spaces --no more, no less-- ? Yes. > > All tests I did result in the same hash, not depending on the use of > -b or -t or no option. Yes, but I was speaking of the -c option only, the option that actually checks the hash against an actual file(s) or archive. I discovered this when downloading tgz or bz2 files and a properly formated md5 file is not provided, only the actual hash. A cut n' paste into a file of the proper name requires 2 spaces between the hash and the filename. I don't know about all *nix OSs, but in Slack, formatting with 1 space results in this output: md5sum: foo.md5: no properly formatted MD5 checksum lines found .....while formatting with 3 spaces results in this: md5sum: foo: No such file or directory foo: FAILED open or read md5sum: WARNING: 1 of 1 listed file could not be read Only 2 spaces will generate the desired response. Naturally, if the hash is wrong, you'll get an error: md5sum: WARNING: 1 of 1 computed checksum did NOT match I don't know what you get, but this is how it works for me on all the Slack installs I've used. A properly formatted .md5 file will work for a single file or an archive containing multiple files. nb |
| ||||
| notbob wrote: > On 2006-11-04, Kees Theunissen <theuniss@rijnh.nl> wrote: >> Are you sure about that format: two spaces --no more, no less-- ? > > Yes. > >> All tests I did result in the same hash, not depending on the use of >> -b or -t or no option. > > Yes, but I was speaking of the -c option only, the option that > actually checks the hash against an actual file(s) or archive. > > I discovered this when downloading tgz or bz2 files and a properly > formated md5 file is not provided, only the actual hash. A cut n' > paste into a file of the proper name requires 2 spaces between the > hash and the filename. Been there. Done exactly that. But there still is that other version of the format with a space and an asterix as a separator. And 'md5sum -c' is happy to accept that format: kees@lankhmar:~$ md5sum /etc/passwd|sed -e 's/ / */'|md5sum -c /etc/passwd: OK It might be getting off topic, and it certainly isn't the question of the OP. But his question has been answered a few times. Lets hijack this threat. You described how to reconstruct a md5 checksum file from a given hash and a file name, and I want to elaborate a little on that. I'm just wondering if there are any cases where there _is_ a difference between " " and " *" as a separator. Are there any cases where an asterix should be used? In the limited testing I did I didn't notice any difference between using " " or " *" as a separator. The md5sum(1) manpage says: -b, --binary read in binary mode -t, --text read in text mode (default) Is there any special handling of "text" files, whatever that might be? It probably is a mind twist; my mind _is_ preloaded. I think about differences between "bin" and "ascii" in ftp downloads. I think about the following options of "diff" -E --ignore-tab-expansion Ignore changes due to tab expansion. -b --ignore-space-change Ignore changes in the amount of white space. -w --ignore-all-space Ignore all white space. -B --ignore-blank-lines Ignore changes whose lines are all blank. And I'm wondering what is special about the "text" mode of md5sum. Does it handle line endings or consecutive white space characters in a special way? Does it perform some kind of normalizing the file before calculating the hash? I can't find any differences between "-t" and "-b". even this runs without problems: kees@lankhmar:~/slackware-11.0$ sed -e 's/ / */' CHECKSUMS.md5 \ | md5sum -c | grep -v OK$ And I'm still wondering if there are any cases where a "*" should be used when reconstructing a md5 checksum file from a given hash and a filename. Forget about it. I'm wasting your time. (I'm still posting this, else it would have been a waste of my time too :-) While I'm writing this, and thinking more about it than I did before, it comes in mind that some (obscure) operating systems make difference between binary reads of a file and text reads. Think about msdos and the difference between copy /b infile outfile and copy /a infile outfile The /a (ascii mode) variant will copy all bytes of infile until an end of file char (^Z) and ignore the rest of the file. Specifying -t or -b for md5sum, and using " " or " *" as a separator, would certainly make a difference on such an operating system. On Unix/Linux there is probably no difference. Sorry for wasting your time, Kees. -- Kees Theunissen. |