From owner-freebsd-questions@FreeBSD.ORG Tue May 11 19:27:44 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0269A106566B for ; Tue, 11 May 2010 19:27:44 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id B18EA8FC2C for ; Tue, 11 May 2010 19:27:43 +0000 (UTC) Received: by vws12 with SMTP id 12so952937vws.13 for ; Tue, 11 May 2010 12:27:42 -0700 (PDT) Received: by 10.220.60.201 with SMTP id q9mr474824vch.160.1273606062647; Tue, 11 May 2010 12:27:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.122.31 with HTTP; Tue, 11 May 2010 12:27:22 -0700 (PDT) In-Reply-To: <20100511175621.4B861BE5F@bsd118.wpafb.af.mil> References: <20100511175621.4B861BE5F@bsd118.wpafb.af.mil> From: Eitan Adler Date: Tue, 11 May 2010 22:27:22 +0300 Message-ID: To: vogelke+unix@pobox.com Content-Type: multipart/mixed; boundary=e0cb4e887e21f2af110486568423 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-questions@freebsd.org, David Allen Subject: Re: md5(1) and cal(1) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2010 19:27:44 -0000 --e0cb4e887e21f2af110486568423 Content-Type: text/plain; charset=UTF-8 > D> 2. Why doesn't md5(1) have a "check" option? Seems to me requiring a > D> manual inspection is error-prone at best, and makes scripting > D> unecessarily complicated. > Would something like the attached patch be good? It adds a -c option for a string to check against. It prints "[failed]" if the string does not match the files md5 unless in -q mode. It also returns 2 to indicate md5 match failure for use in scripts. --e0cb4e887e21f2af110486568423 Content-Type: application/octet-stream; name="md5-check.patch" Content-Disposition: attachment; filename="md5-check.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g9345t3k0 SW5kZXg6IG1kNS4xCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIG1kNS4xCShyZXZpc2lvbiAyMDc0MzMpCisrKyBt ZDUuMQkod29ya2luZyBjb3B5KQpAQCAtNzMsNiArNzMsOCBAQAogVGhlIGhleGFkZWNpbWFsIGNo ZWNrc3VtIG9mIGVhY2ggZmlsZSBsaXN0ZWQgb24gdGhlIGNvbW1hbmQgbGluZSBpcyBwcmludGVk CiBhZnRlciB0aGUgb3B0aW9ucyBhcmUgcHJvY2Vzc2VkLgogLkJsIC10YWcgLXdpZHRoIGluZGVu dAorLkl0IEZsIGMgQXIgc3RyaW5nCitDb21wYXJlIGZpbGVzIHRvIHRoaXMgbWQ1IHN0cmluZwog Lkl0IEZsIHMgQXIgc3RyaW5nCiBQcmludCBhIGNoZWNrc3VtIG9mIHRoZSBnaXZlbgogLkFyIHN0 cmluZyAuCkBAIC0xMDEsNyArMTAzLDggQEAKIGFuZAogLk5tIHJtZDE2MAogdXRpbGl0aWVzIGV4 aXQgMCBvbiBzdWNjZXNzLAotYW5kIDEgaWYgYXQgbGVhc3Qgb25lIG9mIHRoZSBpbnB1dCBmaWxl cyBjb3VsZCBub3QgYmUgcmVhZC4KKzEgaWYgYXQgbGVhc3Qgb25lIG9mIHRoZSBpbnB1dCBmaWxl cyBjb3VsZCBub3QgYmUgcmVhZCwKK2FuZCAyIGlmIGF0IGxlYXN0IG9uZSBmaWxlIGRvZXMgbm90 IGhhdmUgdGhlIHNhbWUgaGFzaCBhcyB0aGUgLWMgb3B0aW9uLgogLlNoIFNFRSBBTFNPCiAuWHIg Y2tzdW0gMSAsCiAuWHIgbWQ1IDMgLApJbmRleDogbWQ1LmMKPT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09P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