大网数据广告活动
服务器运维问答

How to extract rpm preamble

· 52CE 我爱测

I am working on a non-redhat based machine and I need to extract Version: x.y.z and Release: a.b.c information from some .rpms that pass across the machine. Typically one would do: rpm -qip ./Foo.x.y.z.rpm | grep Version | awk ..…

问题原文

原帖链接 · nolandda · CC BY-SA 4.0

I am working on a non-redhat based machine and I need to extract Version: x.y.z and Release: a.b.c information from some .rpms that pass across the machine.

Typically one would do:

rpm -qip ./Foo.x.y.z.rpm | grep Version | awk ...

But this isn't a redhat-based machine so I don't have rpm and I don't really want to install a 2nd package manager anyway.

I thought that if I did:

rpm2cpio ./Foo.x.y.z.rpm | cpio -idmv

Then when the cpio was extracted I would find some file named .preamble or something that would have the data in it. But no luck. Anyone know another way?

已采纳解答

原帖链接 · John Mahowald · CC BY-SA 4.0

rpm2cpio use case is to extract files without the metadata, the opposite of what you want. It like other tools requires linking against librpm. Even Midnight Commander exploring an rpm file uses the rpm binary.

On an system with yum, use createrepo to create a repository from these rpms. XML and sqlite will be generated with the metadata. While easier to parse than the rpm binary format, you will have to write the queries yourself if you are not using yum. Keep the repodata so you have a functional yum repo.

Going up yet another level of abstraction, systems lifecycle tools include content management. Namely, Katello or Red Hat Satellite. A bit heavyweight compared to a shell script, but you can get hosts and the packages they subscribe to with an API.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。