–Edit.
Originally, I had run into the issue of trying to determine the *nix distribution – a command that would tell me the distribution and the build and everythign else I wanted to know. After reviewing some of the awesome comments left behind, here’s the updated perl script to determine the distribution (in Perl).
#!/usr/bin/env perl
use strict;
use warnings;
my ( $distro );
$distro = `lsb_release -i -s`;
chomp $distro;
my %installCmd = (
"Fedora" => \&fedora,
"Ubuntu" => \&ubuntu,
);
&test();
sub test {
if ( exists $installCmd{$distro} ) {
$installCmd{$distro}->();
} else {
print "Supported Distributions are: ". join(', ' , keys %installCmd) . ".\n";
exit;
}
}
sub fedora { print "Hello from the Fedora Family!"; }
sub ubuntu { print "Hello from UBUNTU!!!"; }
Determining distro:
Try:
cat /etc/issue
/etc/issue is typically the banner for ssh logins, and some people may find a need to change that banner to either a) mask what os they’re running or b) write a disclaimer or something for those logging into the system.
falls under UserError, imo.
uname -v does display ‘Ubuntu’ as part of the kernel version. What about Fedora?
uname -v (in fedora)
returns #1 SMP Fri Dec 4 00:43:59 EST 2009
Try parsing the contents of /etc/lsb-release
Fedora doesn’t have an /etc/lsb-release….fedora has /etc/system-release which is symlink to /etc/fedora-release
lsb_release -a
On a Fedora box would give you something like this:
LSB Version: :core-3.1-ia32:core-3.1-noarch:core-3.2-ia32:core-3.2-noarch:desktop-3.1-ia32:desktop-3.1-noarch:desktop-3.2-ia32:desktop-3.2-noarch
Distributor ID: Fedora
Description: Fedora release 12 (Constantine)
Release: 12
Codename: Constantine
The same command will work on Ubuntu / Debian too.
etank, that’s great. I didn’t even consider the lsb_release (underline)…kept trying the lsb-release in fedora, since the /etc/lsb-release in ubuntu…
Works great, thanks mate!
On Fedora if you do:
uname -a
You get something like:
Linux carter 2.6.31.6-162.fc12.i686.PAE #1 SMP Fri Dec 4 00:43:59 EST 2009 i686 i686 i386 GNU/Linux
Notice the fc12 in the string. That means I am running Fedora 12.
ya, i’m not looking for the fc12 or anything like that…I want something that will be uniform throughout, across all platforms of linux (preferably).
will the lsb_release -a work with slax, mandrake, gentoo and other distros as well?
It should. -a gives you everything though, for just the distributor, you want -i (see man page for other options)
Facter will give you a lot of informations, you need facter anyway if you use puppet… you use puppet, right ?
;-)
No, never even heard of puppet or facter
Give it a shot, especially with what you’re trying to achieve (modular, cross distribution setup/config management).
Example run here :
Facter : http://pastebin.com/f5a2fae61
Puppet : http://bitfieldconsulting.com/agile-sysadmin
Use the -s flag to get the short answer:
alex@dv9000-ubuntu:~$ lsb_release -i -s
Ubuntu
For Ubuntu,
cat /proc/version
and of course
cat /etc/lsb-release
And cat /etc/debian_version though this may kinda confused some :P
I was looking for a command that is universal among linux distros….and so far it seems that lsb_release is that command.
“cat /etc/*release” should work on most Linux distros and will work on most Unixes.