3

Possible Duplicate:
How do I find out what version of Linux is running?

What is the best way to get the flavor of linux installed on any server? For example if the server is RedHat or CentOS, I can simply do:

cat /etc/redhat-release
CentOS release 6.3 (Final)

Where do all the other major distributions store their details file? Thanks.

Justin
  • 5,008
  • 19
  • 58
  • 82

4 Answers4

3

Well, how many variants are you looking at? RHEL (and clones) and Debian and Ubuntu.

Ideally, lsb_release -i -s output would work... But there may be cases where that command is not available.

A more comprehensive example is available at: How do I find out what version of Linux is running?

ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • `python -c 'import platform ; print platform.dist()[0]'` seems to work on CentOS, do you have access to a Debian based distro to try it? – Justin Sep 21 '12 at 02:48
  • Yes. I got: `root@deore:/volumes# python -c 'import platform ; print platform.dist()[0]' Ubuntu` – ewwhite Sep 21 '12 at 02:58
  • Also `lsb_release` is not available on CentOS. :( – Justin Sep 21 '12 at 03:06
  • @Justin `[root@xt ~]# lsb_release -i Distributor ID: CentOS` The name of the package is `redhat-lsb`. – ewwhite Sep 21 '12 at 08:58
2

Odd that no one mentioned /etc/issue in the previously linked example. I've used that file for years.

Nowadays I just use 'facter' with Puppet to get that information, grep & awk the output.

Magellan
  • 4,431
  • 3
  • 29
  • 53
0

FusionInventory is a cross-platform lightweight inventory tool that can get this informaton on many Linux distros but also on BSDs, Windows, MacOS X and other unices.

If available, they use lsb_release as described by @ewwhite above, but if not they have a very useful list of files and regular expressions to check the distro name and version: https://github.com/fusinv/fusioninventory-agent/blob/2.2.x/lib/FusionInventory/Agent/Task/Inventory/Input/Linux/Distro/NonLSB.pm#L16.

I would recommend using FusionInventoy itself to get this information, rather than reimplementing your own scripts with this logic, as their community will maintain this functionality up to date. You could either use the agent on it's own (it outputs a XML/JSON file which is easy to parse) or couple it with a wider solution to manage the machines in your network like GLPI or Rudder, depending on your needs.

Jonathan Clarke
  • 1,657
  • 2
  • 11
  • 25
0

You can use facter to find out a lot of details in a nicely normalized way. It's part of puppet.

Sirex
  • 5,447
  • 2
  • 32
  • 54