Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to identify what linux version is running

Posted on 2007-12-06
11
Medium Priority
?
4,713 Views
Last Modified: 2013-12-06
Hello,
 I need to include in a setup script for Linux what I am running so that I can install the appropriate libraries.
I need to know if I am running ES 3.0, 4.0 or 5.0.
I am currently using redhat-release file to do that.  Apparently this is not a good method because some Linux versions (like CentOS) don't have that file.  
I need a better - more general - method to identify what Linux is running on the computer.
I am most interested in redhat releases but if there is something I can use with other distributions that would be great.
The actual bash lines needed would be very much appreciated.
I
Thanks
0
Comment
Question by:atoncelli
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 7

Expert Comment

by:killbrad
ID: 20421276
# uname -a

# cat /etc/issue
0
 
LVL 3

Expert Comment

by:thigger_uk
ID: 20421424
cat /etc/*release  will help as many other distros will have their own release files (eg SuSE)

I was under the impression that CentOS still used /etc/redhat-release though
0
 
LVL 7

Expert Comment

by:killbrad
ID: 20421458
thigger:

[user@centos ~]# cat /etc/issue
CentOS release 5 (Final)

[user@centos ~]# cat /etc/redhat-release
CentOS release 5 (Final)

Both still work, but might as well use /etc/issue since it's more universal.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:thigger_uk
ID: 20421526
True, however the downside of /etc/issue is that I've seen a number of systems where it's been modified to create a 'Welcome' screen.
(for the benefit of others, /etc/issue is the file which is displayed before login and usually contains information about the system as above)
0
 
LVL 7

Expert Comment

by:killbrad
ID: 20421552
thigger:  then they are not properly administering their system, as the /etc/motd file is meant for the Message of the Day, printed after login.  

It isn't a bad idea to change the /etc/issue file to give intruders less information to work with, but an active or passive scanning of the system with nmap would be able to ID the system pretty accurately anyways.

uname -a  still will print out your kernel version at least.

wanna fight?  :-)    
0
 
LVL 3

Expert Comment

by:thigger_uk
ID: 20421612
You're right it's a bad idea... sadly it happens :) And that sort of admin is much less likely to play with the /etc/*releases files. And, as you point out there are those who remove data from /etc/issue which would also make it less reliable.

But I'm a great fan of 'uname -a' :)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20422929
So how does uname -a distinguish between CentOS and RHEL?  Rhetorical question, as it can't.

/etc/motd and /etc/issue have different functions.  /etc/issue is displayed *before* login (default for telnet and not for ssh), whereas /etc/motd is displayed as part of the login process by the shell.

Most systems will/should have /etc/issue modified to display a security/TOS message.

Anyway, getting back to the original question, if you are only concerned with RHEL and CentOS, then using the contents of /etc/redhat-release is fine.

Alternatively, you can do

rpm -qa|grep release
0
 

Author Comment

by:atoncelli
ID: 20426959
Is it possible to use:
#cat /etc/issue
or it is modified to store TOS messages?
If that's the case I can't really base an installation on that command.
If I can, what stringam I looking for?
<release [3|4|5]>?
I only have redhat available (3,4 and 5) so I can't test CentOS.


What I mainly need is to figure out if I am running a distribution of redhat or not.  If it's redhat I need to know the release version (3,4,5,...). If it isn't a redhat distribution , I need to exit the installation.
Are there other distribution of redhat beyond redhat itself and CentOS?

Thanks
0
 
LVL 3

Assisted Solution

by:thigger_uk
thigger_uk earned 300 total points
ID: 20428696
Mandrake/Mandriva is close enough to redhat to count as it for most purposes.

I guess your best method is to check for the existence of an /etc/redhat-release file (for CentOS, Redhat) or an /etc/mandrake-release. Then check the words in the file.

If the first word is 'CentOS' then the release will be the third word (cat /etc/redhat-release | awk '{print $3}')

If the first word is 'Red' (and the second 'Hat') then the release number will be the fifth word (except in RedHat Enterprise where it's the seventh - you can spot Enterprise as the third word will be 'Enterprise')

Some example /etc/redhat-release files to test:

Red Hat Enterprise Linux ES release 3 (Taroon Update 4)

Red Hat Linux release 6.0 (Hedwig)

CentOS release 5 (Final)



http://kbase.redhat.com/faq/FAQ_79_4422.shtm - for some more info

http://www.novell.com/coolsolutions/feature/11251.html - a handy script I found whilst searching

0
 
LVL 48

Accepted Solution

by:
Tintin earned 400 total points
ID: 20439974
Don't get confused between using the term Redhat and Redhat Enterprise Linux (RHEL).  When people use the term Redhat, they usually mean Redhat <=9.0 or sometimes even Fedora.

The following should successfully extract the Redhat/CentOS version number.

version=`rpm -qa | grep release | cut -f3 -d-
0
 
LVL 2

Expert Comment

by:jscase
ID: 20496334
Is there a specific library or kernel version you're looking for? Once you get beyond RedHat to Suse, Debian it's going to be difficult to categorize the whole release in a consistent way, but you may be able to determine the version of gcc more conistently (for example). If you can come up with a table of version dependencies that may have broader utility than a single release file.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question