simple script detect to find OS version/flavour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple script detect to find OS version/flavour
# 1  
Old 08-13-2008
simple script detect to find OS version/flavour

Hi,

A newbie question.


Following script gives no output.
===============================

root@srv [~]# cat /etc/redhat-release | awk {'print $1}'
Red

root@srv [~]# cat 123.sh
if (( `cat /etc/redhat-release | awk {'print $1}'` != CentOS )); then { echo "System runs on Redhat Linux. Exiting..."; exit; } fi


root@srv [~]# sh 123.sh
root@srv [~]#

root@srv [~]# if (( `cat /etc/redhat-release | awk {'print $1}'` != CentOS )); then { echo "System runs on Redhat Linux. Exiting..."; exit; } fi
root@srv [~]#



root@srv [~]# sh -x 123.sh
++ cat /etc/redhat-release
++ awk '{print $1}'
+ (( Red != CentOS ))


root@srv [~]#


Please advise or provide a alternative so that I can include it in a shell script that will use up2date, in case it is RHEL ( i am aware RHEL 5 use yum ) and will use yum incase it is CentOS


Thanks

Last edited by fed.linuxgossip; 08-13-2008 at 11:37 AM..
# 2  
Old 08-13-2008
OS=`cat /etc/redhat-release | awk {'print $1}'`
if [ "$OS" != "CentOS" ]
then
echo "System runs on Redhat Linux. Exiting...";
exit;
fi
# 3  
Old 08-13-2008
Does CentOS have the /etc/redhat-release file?

Just test for the existence of the file
Code:
if [[ -f /etc/redhat-release ]] ; then
  OS=redhat
else
  OS=CentOS
fi

# 4  
Old 08-13-2008
Hi,

CentOS does have /etc/redhat-release file
# 5  
Old 08-13-2008
Thanks palsevlohit_123 , it works. Lets extend script abit.

Updating in a moment
# 6  
Old 08-13-2008
If /etc/redhat-release doesnot exit , echo system not running redhat or CentOS or redhat-release file is missing, then do nothing below, if /etc/redhat-release exists , then find the OS flavour and,

## if system is Redhat
OS=`cat /etc/redhat-release | awk {'print $1}'`
if [ "$OS" != "CentOS" ]
then
echo "System runs on Redhat Linux.";

do
up2date -i ncurses dialog nmap
done
exit;
fi

## if system is Centos
echo "System runs on CentOS.";
do
yum -y install ncurses dialog nmap
done



I can run the above script two times and one of them will do the install, yum or up2date. I will look better , if we use the value ( Red or CentOS ) and then build a script like ( nested or whatever you call )


If /etc/redhat-release doesnot exit , echo system not running redhat or CentOS or redhat-release file is missing, then do nothing below

else

OS=`cat /etc/redhat-release | awk {'print $1}'`
if [ "$OS" != "CentOS" ]
then
echo "System runs on Redhat Linux.";
then use the up2date command
else if system runs Centos
then use the yum comand
done
# 7  
Old 08-13-2008
Please try

cat /proc/version

and Grep for words "Red" and "CentOS" you can event get the version from the same.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HELP simple script to find e-mail address on a file

Hello guys, im new to to unix/linux i have a text file like this: person1@test.com iisiiasasas person2@test.com 123w2 3233 sajsja person3@test.com jsajjsa sajsjasaj person4@test.com I want to extract only e-mail address and get rid of all other stuff, i want an output like this ... (4 Replies)
Discussion started by: RazorMX
4 Replies

2. UNIX for Dummies Questions & Answers

Help with simple script to find PID of process

Hi everyone. I've been reading around and am a little bit overwhelmed, hoping to find a kind soul out there to hold my hand through writing my first script. This need has emerged at work and I haven't much experience writing shell scripts, but this is a problem we have with a production environment... (13 Replies)
Discussion started by: thirdcoaster
13 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. UNIX for Dummies Questions & Answers

Simple version control script for text files

HI guys, Could you help me writing a simple version control script for a text files. the format could be ./version_control <file(s)> (I want it to be able to work with more than 1 file at the same time) commands are add and get, add means you add new file(s) to the archive, get means you... (4 Replies)
Discussion started by: s3270226
4 Replies

5. Shell Programming and Scripting

Simple script to find common strings in two files

Hi , I want to write a simple script. I have two files file1: BCSpeciality Backend CB CBAPQualDisp CBCimsVFTRCK CBDSNQualDisp CBDefault CBDisney CBFaxMCGen CBMCGeneral CBMCQualDisp file2: CSpeciality Backend (8 Replies)
Discussion started by: ramky79
8 Replies

6. Shell Programming and Scripting

script to find filenames with latest version and for all seq. numbers in a day

Hi, We have a requirement to find the set of filenames from the group of files in a specified folder based on (i) version number (ii) sequence number such that, for any given sequence number in a day only the latest version filenames have to indentified. Below is the format of... (4 Replies)
Discussion started by: Deepakbabu
4 Replies

7. Shell Programming and Scripting

Simple shell script to find and print data

Hi, I have a log file containing data on emails sent. Looks a bit like this for one email: Content-Type: text/plain; charset="UTF-8" Date: 12 Jun 2008 14:04:59 +0100 From: from@email.com Subject: xcf4564xzcv To: recip@email.co.uk Size = 364 Jun 12 14:04 smtp_234sldfh.tmp I need to... (5 Replies)
Discussion started by: terry2009
5 Replies

8. Shell Programming and Scripting

Simple Find file Script.....

Im trying to make a very simple find the first file with the .zip extension in a specific folder and open that file. The folder path and file name will vary every-time and it may contain spaces. If I try to look For this example the folder directory is /Users/username/Desktop/testfolder/abc... (6 Replies)
Discussion started by: elbombillo
6 Replies

9. UNIX for Dummies Questions & Answers

find command to detect installations

Hi I'm wondering how I can find all the files which were installed on certain date? For example: I'm looking for alle the files which were installed on the 11.09.06 on the system. Does somebody know how to do this? Thanks Reto (2 Replies)
Discussion started by: goldenglobe
2 Replies

10. Shell Programming and Scripting

simple script to find the number of "tab"s...but,...

------------------------------ $x=" hi"; $tabspace=0; while ($x =~ /\t/g ) { $tabspace++; } print $tabspace; --------------------------------- 1.)when i tried it without "g" ($x = ~/\t/ )... when i run the script it utilizes around 95% cpu and system hangs and i did "End process"... (0 Replies)
Discussion started by: sekar sundaram
0 Replies
Login or Register to Ask a Question