We help IT Professionals succeed at work.

How to determine Linux distro in a script

jbbarnes
jbbarnes asked
on
I have some system report scripts that need to determine the Linux distro they are running under.

Webmin (which is perl based) can tell you the OS is "Ubuntu Linux 8.04.2". How can I do that?

I am already parsing out a lot of information from /proc or from the output of commands like uptime or uname. I could also read a file in the /etc directory.

This script happens to be in php, but any solution using proc, utility output, or config file parsing is fine. I just need to know where to look.

Thanks.
Comment
Watch Question

You should be able to parse the info you want from "uname -a".

Author

Commented:
That's what I was thinking, too, but unfortunately it's not there:

Linux ip-xxx-xxx-xxx-xxx.ip.secureserver.net 2.6.24-23-server #1 SMP Wed Apr 1 22:22:14 UTC 2009 i686 GNU/Linux

I would need to know the actual distribution name and version.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Do you have the file:  /etc/issue? It should be there.

Author

Commented:
That's just what I needed. Thanks.
Most Valuable Expert 2011
Top Expert 2015

Commented:
NP. Glad to help  :)
Top Expert 2007

Commented:
/etc/*release*

is more reliable than /etc/issue as /etc/issue may be overwritten with custom information.

Author

Commented:
I have an /etc/lsb-release and that one is cleaner:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.2"

Is there a unix utility that lets you specify a file name and key (like /etc/lsb-release , "DISTRIB_DESCRIPTION") that will return just the value of that one line in the file?
Most Valuable Expert 2011
Top Expert 2015

Commented:
Someone more Linux-y than I may be able to come up with something smoother, but the following should work:

    cat /etc/lsb-release | grep DISTRIB_DESCRIPTION | cut -d= -f2