linux 使用命令行或bash从yum存储库文件中的文件提取第二个单词

s3fp2yjn  于 2022-11-02  发布在  Linux
关注(0)|答案(2)|浏览(141)

我想从文本文件(yum存储库文件)中提取特定的文件路径。文件内容如下所示

[rhel-8-for-x86_64-baseos-rpms]
name = Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
baseurl = https://myhost.com
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslclientkey = /etc/pki/entitlement/60472949067-key.pem
sslclientcert = /etc/pki/entitlement/604712349067.pem
metadata_expire = 1
enabled_metadata = 1

[rhel-8-for-x86_64-appstream-rpms]
name = Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
baseurl = https://myhost.com
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslclientkey = /etc/pki/entitlement/6047297349067-key.pem
sslclientcert = /etc/pki/entitlement/6047297349067.pem
metadata_expire = 1
enabled_metadata = 1

我的要求是通过命令行或脚本提取rhel-8-for-x86_64-appstream-rpm和rhel-8-for-x86_64-baseos-rpm的sslclinetkey路径
任何帮助都将不胜感激

  • 更新 *

我尝试过这种方法,但我得到多个条目

cat /etc/yum.repos.d/redhat.repo  | grep sslclientkey | awk '{print $3}'
/etc/pki/entitlement/2627848977587647846-key.pem
/etc/pki/entitlement/7675461792121821585-key.pem
/etc/pki/entitlement/3236342435348109549-key.pem
/etc/pki/entitlement/60472974412349067-key.pem
/etc/pki/entitlement/3236342435348109549-key.pem
/etc/pki/entitlement/60472974412349067-key.pem

但我只需要rhel-8用于x86_64-appstream-rpm和rhel-8用于x86_64-baseos-rpm

zhte4eai

zhte4eai1#

awk -F' = ' '/sslclientcert/{print $2}' file 

# or

awk '/sslclientcert/{print $3}' file 

/etc/pki/entitlement/604712349067.pem
/etc/pki/entitlement/6047297349067.pem

awk -F' = ' '/\[.*\]/ {printf "%s ", $1} /sslclientcert/{print $2}' file 
[rhel-8-for-x86_64-baseos-rpms] /etc/pki/entitlement/604712349067.pem
[rhel-8-for-x86_64-appstream-rpms] /etc/pki/entitlement/6047297349067.pem
m4pnthwp

m4pnthwp2#

它只是ini文件.所以crudini将做这项工作:

crudini --get /etc/yum.repos.d/redhat.repo rhel-8-for-x86_64-appstream-rpms sslclientkey

或对于所有部分:

for i in in `crudini --get /etc/yum.repos.d/redhat.repo`; do
  crudini --get /etc/yum.repos.d/redhat.repo "$i" sslclientkey
done

相关问题