I have tried to look for an answer on how this may be done but I cannot seem to find one. I am aware that to find the OS name in perl you can use
$^O
However in Linux and Solaris, no matter what OS version you are on it will just return either Solaris or Linux. I would like it to show up as Solaris10 or Solaris11. Is there a way to get this? I know if you enter
uname -r
you can get the version number (5.10 in Solaris for example). Any thoughts on how this could be done?
Thank you =)
The POSIX module in perl provides the uname call, so:
use POSIX qw(uname);
my @uname = uname();
print $uname[0] . " " . $uname[2];
This provides the information from the running system, not from the system that performed the build (which is where the Config results come from).
In general, though, this information is the kernel release, and not the marketing version of the product, so for example, this wouldn't tell you if it's a Linux Mint system, just that it's a Linux system running the 3.2.foo kernel.
For lsb based Linux systems, the lsb_release command can give this information e.g. on a linux system I have:
natsu ~> lsb_release -r
Release: 12.04
natsu ~> lsb_release -i
Distributor ID: Ubuntu
This information is in the /etc/lsb-release file.
For Solaris, the release information is in the /etc/release file. The first line contains the name of the operating system e.g. Solaris 10 9/10. There are multiple lines in this file, and it's more of a free-form text field.
use Config;
print "$_\n" for @Config{qw(myuname osname osvers)};
From perldoc Config,
The Config module contains all the information that was available to the Configure program at Perl build time.
myuname
The output of uname -a if available, otherwise the hostname. The whole thing is then lower-cased and slashes and single quotes are removed.
osname
This variable contains the operating system name (e.g. sunos, solaris, hpux, etc.). It can be useful later on for setting defaults. Any spaces are replaced with underscores. It is set to a null string if we can't figure it out.
osvers
This variable contains the operating system version (e.g. 4.1.3, 5.2, etc.). It is primarily used for helping select an appropriate hints file, but might be useful elsewhere for setting defaults. It is set to '' if we can't figure it out. We try to be flexible about how much of the version number to keep, e.g. if 4.1.1, 4.1.2, and 4.1.3 are essentially the same for this package, hints files might just be os_4.0 or os_4.1, etc., not keeping separate files for each little release.