Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to identify what linux version is running

Posted on 2007-12-06
11
Medium Priority
?
4,711 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

After running Ubuntu some time, you will be asked to download updates for fixing bugs and security updates. All the packages you download replace the previous ones, except for the kernel, also called "linux-image". This is due to the fact that w…
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

705 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