以下摘自stackoverflow:
Most distro uses the distroverpkg version to get the releasever and basearch.
If you look at /etc/yum.conf, you will see that distrover is set to redhat-release (for RHEL), enterpriselinux-release (for OEL), and others.
To get the package name:
distro=$(sed -n 's/^distroverpkg=//p' /etc/yum.conf)
To get the releasever:
releasever=$(rpm -q --qf "%{version}" -f /etc/$distro)
To get the basearch:
basearch=$(rpm -q --qf "%{arch}" -f /etc/$distro)
The new code above will try to get the package associated with a file /etc/$distro. Some Linux adds /etc/redhat-release to their package release.
If you get file not owned by any package then use the /etc/*-release file that came with your distro. It is probably /etc/centos-release.
You can check the appropriate /etc/*-release appropriate for this code by checking which file is packaged with centos.
rpm -qf /etc/*-release
Then use this file instead of the first line above.
distro=/etc/centos-release
Here's an example from OEL where /etc/redhat-release is packaged as enterprise-release.
rpm -q --qf "%{name}" -f /etc/redhat-release
总结:
$releasever是取自distro的软件包比如,cent7.2是取centos-release-7-2.1511.el7.centos.2.10.x86_64的version字段;
$basearch是取centos-release-7-2.1511.el7.centos.2.10.x86_64的arch字段。
本文介绍了如何通过shell脚本从Linux系统的配置文件中提取发行版的名称、版本号及架构等信息。具体步骤包括确定配置文件路径、使用sed命令提取版本包名、利用rpm命令查询版本号与架构。
961

被折叠的 条评论
为什么被折叠?



