Determine the OS version of an OEL linux box?
The usual methods to determine the OS versions seem to be viewing
/etc/*-release file
*here would be the family to which the particular version of the OS belongs to. But on the OEL system, the following files are present and all of them seem to be returning valid release versions, in such situations is there a definite method of determining the OS release version details :
cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
cat /etc/enterprise-release
Enterprise Linux Enterprise Linux Server release 5.8 (Carthage)
cat /etc/oracle-release
Oracle Linux Server release 5.8
cat /etc/*release*
Enterprise Linux Enterprise Linux Server release 5.8 (Carthage)
Oracle Linux Server release 5.8
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
using alternatives as mentioned below are used only in case the above files don't return valid values :
lsb_release -a returns the same output as returned by enterprise-release
Update 1 : context of execution
The /etc/*-release file is examined as a part of a programmatic solution, the value of * is provided by a dummy file which can have these values :
asianux,enterprise,mandrake,redhat,UnitedLinux,Suse,SuSE
depending on the order of appearance in the above scenario since enterprise appears first /etc/enterprise-release file is queried to find the OS version In case the ordering was otherwise with redhat appearing before enterprise /etc/redhat-release would be used.
This does not seem to be a viable solution hence seeking other more definite methods for determining the version of the OS.
Solution 1:
lsb_release -a
See Linux Standard Base documentation
As per your question you mention this as an alternative in case the above do not work. You should use lsb_release
first as it is the standard.
Also it should return more information than the enterprise-release
command, specifically the LSB Version line (eg, lsb_release -v
)
Solution 2:
(Are Mandrake, AsianUX and UnitedLinux still around enough to certify compatibility on new software?)
Definitely check the suggestions at: What version of RHEL am I using?
But beyond that, look at facter if you have some control over the systems this software will be deployed on. If this is software that will be shipped and run on systems that you don't manage, then you'll likely have to have to handle OS-detection. If it is your company/environment, facter
is the cleanest method.
When dealing with RHEL and its derivatives, it's important to know that the distribution lifecycle strives to maintain compatibility between minor releases. So software should be able to run on *EL5.4, 5.8 and 5.10, for example. I don't think that's your issue here, though, as you probably only care about the OS "family".
Look at the facter
output from the following three systems.
# facter operatingsystem operatingsystemmajrelease operatingsystemrelease osfamily
operatingsystem => RedHat
operatingsystemmajrelease => 5
operatingsystemrelease => 5.8
osfamily => RedHat
and
# facter operatingsystem operatingsystemmajrelease operatingsystemrelease osfamily
operatingsystem => CentOS
operatingsystemmajrelease => 5
operatingsystemrelease => 5.9
osfamily => RedHat
and
# facter operatingsystem operatingsystemmajrelease operatingsystemrelease osfamily
operatingsystem => CentOS
operatingsystemmajrelease => 6
operatingsystemrelease => 6.5
osfamily => RedHat
They're CentOS and RHEL, versions 5.8, 5.9 and 6.5. But I think you probably only care that they're RedHat derivatives. I'd be using the osfamily
and maybe the operatingsystemmajrelease
fact.
Take a look at the OS-detection routine that facter
uses...
https://github.com/puppetlabs/facter/blob/master/lib/facter/operatingsystem/linux.rb
snip
if FileTest.exists?("/etc/enterprise-release")
if FileTest.exists?("/etc/ovs-release")
operatingsystem = "OVS"
else
operatingsystem = "OEL"
end
elsif FileTest.exists?("/etc/redhat-release")
operatingsystem = get_redhat_operatingsystem_name
snip
def get_redhat_operatingsystem_name
txt = File.read("/etc/redhat-release")
matches = {
"CentOS" => "centos",
"Scientific" => "Scientific",
"CloudLinux" => "^cloudlinux",
"PSBM" => "^Parallels Server Bare Metal",
"Ascendos" => "Ascendos",
"XenServer" => "^XenServer",
"XCP" => "XCP"
}
In short, Oracle Enterprise Linux detection totally hinges on the presence of /etc/enterprise-release
.
[root@xt ~]# facter osfamily
RedHat
[root@xt ~]# facter operatingsystem
CentOS
[root@xt ~]# touch /etc/enterprise-release
[root@xt ~]# facter operatingsystem
OEL
So you're doing this the right way, or at least the same way facter
does.
Solution 3:
There are no definitive/standard methods that will work across all major distributions. You'll have to use extra code to figure it out to the best of your knowledge (based on how you understand each distribution make this information available).
If this is for an installation script, give the user the option of specifying it by hand. If you want o be super nice, try to figure it out yourself and just ask for confirmation.
If this is for a program that will be checking things (and thus need to look at different locations to find them), provide the option of a configuration file or command-line option to specify which distro is being used.
The other solutions provided are great, but you'll depend on code/packages that might not be available everywhere (especially facter, which is by far the most complete tool for gathering information about the environment).