• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4716
  • Last Modified:

How to identify what linux version is running

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
atoncelli
Asked:
atoncelli
  • 4
  • 3
  • 2
  • +2
2 Solutions
 
killbradCommented:
# uname -a

# cat /etc/issue
0
 
thigger_ukCommented:
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
 
killbradCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
thigger_ukCommented:
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
 
killbradCommented:
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
 
thigger_ukCommented:
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
 
TintinCommented:
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
 
atoncelliAuthor Commented:
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
 
thigger_ukCommented:
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
 
TintinCommented:
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
 
jscaseCommented:
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] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now