Solved

How to identify what linux version is running

Posted on 2007-12-06
11
4,683 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Users are often faced with high disk consumption without really knowing where the largest amount of data resides. Disk Usage Analyzer (aka Baobab) is is a graphical, menu-driven application to analyse disk usage in any Gnome environment and can e…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now