Subject: | version for CentOS 7 returns undef |
[ptrost@server linux-geek]$ perl
use warnings;
use strict;
use Linux::Distribution;
my $linux = Linux::Distribution->new;
my $distro = ucfirst $linux->distribution_name();
my $version = $linux->distribution_version();
print "Distro: $distro, Version: $version\n";
On CentOS:
Use of uninitialized value $version in concatenation (.) or string at - line 7.
Distro: Centos, Version:
On ubuntu:
Distro: Ubuntu, Version: 14.04
The issue is that on CentOS 7 the file /etc/centos-release has 'Core' instead of 'Final', so the regex pattern isn't matching:
CentOS Linux release 7.0.1406 (Core)
'centos' => '^CentOS(?: Linux)? release (.+)(?:\s\(Final\))',
Adding an pipe with Core solved it for me:
'centos' => '^CentOS(?: Linux)? release (.+)(?:\s(\(Final\))|\(Core\))',
Interestingly, there's extra spaces at the end of the stock /etc/centos-release file, so I also had to trim the version output.
Post change:
print "Distro: $distro, Version: $version\n";
Distro: Centos, Version: 7.0.1406