Home > database >  Print single line on negative match
Print single line on negative match

Time:10-12

I'm trying to identify rpm files which do not have a signature matching one I plan or do not have a signature at all. I'd like to print just the name of the rpm on a negative match. Example and ideal output below (my signature is 123456 in this example):

/a/folder/rpm_valid_signature.rpm:
    Header V4 RSA/SHA1 Signature, key ID 123456: OK
    Header SHA1 digest: OK (blah)
    V4 RSA/SHA1 Signature, key ID 123456: OK
    MD5 digest: OK (blah)
/a/folder/rpm_invalid_signature.rpm:
    Header V4 RSA/SHA1 Signature, key ID 000000: OK
    Header SHA1 digest: OK (blah)
    V4 RSA/SHA1 Signature, key ID 000000: OK
    MD5 digest: OK (blah)
/a/folder/rpm_unsigned_signature.rpm:
    RSA sha1 (MD5) (PGP) md5 NOT OK (MISSING KEYS: PGP#654321)

Ideally the output should list invalid matches, so: /a/folder/rpm_invalid_signature.rpm (nothing else). I'll use this in a find command and point the script at folders containing about 2k rpm files (either unsigned or signed with an invalid key).

Hope that makes sense, feels like a job for awk or sed but is made much more complex due to repetition in the files.

CodePudding user response:

signature='key ID 123456'  # or whatever should match
find /a/folder -type f -name '*.rpm' -exec grep -L "$signature" '{}'  
  • Related