Community Patterns

Community Library Entry

1

Regular Expression
Created·2021-11-10 23:45
Flavor·PCRE2 (PHP)

/
(?<entropy>\d+)\s*bit\s*(?<algo>\S+)\s*key\s*(?<pubkeyid>[^,]+)
/
gm
Open regex in editor

Description

Record the output of the batch gpg --search-keys commands into variables. For example, get the public key ids or those with *.amazon.com email addresses:

pubkeyids=$(gpg --batch --keyserver hkp://keyserver.ubuntu.com --search-keys amazon.com 2>&1 | grep -Po '\d+\s*bit\s*\S+\s*key\s*[^,]+' | cut -d' ' -f5)

We can automate searching for keys and adding them to the keyring using bash parsing that output. As an illustration, I created the following GitHub gist to host the code below.

Submitted by mavaddat