Solved

How to identify what linux version is running

Posted on 2007-12-06
11
4,691 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
 
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 75 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 100 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Are you sitting there reading this and wondering how to get started with Linux? It almost seems like picking the right Linux distribution is about like picking the right college or buying a new car if you read some of the article out there. Relax… l…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now