LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2012, 04:48 AM   #1
manuabhi
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Rep: Reputation: Disabled
How to differentiate between ubuntu and redhat in unix script or c preprocessor?


Hi,

I am a newbie to linux. I have a file to execute which is copied in different directory based on redhat or ubuntu. Is there any unix script method or c preprocessor by which I can differentiate between Redhat or Ubuntu ?

Is there any other method to differentiate between redhat and ubuntu?
 
Old 07-23-2012, 06:11 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Simply check for the existence of /etc/redhat-release.
 
Old 07-23-2012, 10:00 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
uname -a -m -p
 
Old 07-24-2012, 01:24 AM   #4
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
you can look into the file /etc/issue
 
Old 07-24-2012, 01:29 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

all lsb compliant distros will identify themselves with the lsb_release command. The -i and -s flags will probably give you what you want.
Code:
lsb_release -is
Evo2.
 
Old 07-24-2012, 03:55 AM   #6
manuabhi
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi All,

Thanks for reply. Is there any way I can do with c programming as I am trying to write a cross platform code as well.
 
Old 07-24-2012, 03:57 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,848

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
why do you want to differentiate? usually the same code will run on both.
 
Old 07-24-2012, 04:24 AM   #8
manuabhi
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
@pan64 As i asked in question that we are copying a file in different directory based on whether Redhat or Ubuntu, to execute the file i need to know which linux flavor my code is running.
 
Old 07-24-2012, 04:36 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,848

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
you wrote there is a file to execute copied into a dir. So you want to execute either /use/this/path/app or /use/that/dir/app?
the most simple way is to check if that app exists, fopen(path) is sucessful or not. Any other check you want to implement will be much more complex and will not give you better result.
You can try to open /etc/issue or /etc/redhat-release and parse, execute uname or lsb_release and evaluate the answer from c as well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script to telnet unix to unix and do some task divyashree Programming 10 07-27-2012 02:28 AM
how to differentiate two versions of qt wagmare Linux - Newbie 6 03-09-2009 08:22 AM
how can I differentiate two large text files using shell script? Files are like below surya_gadde Linux - Software 1 01-20-2009 02:52 AM
C pre-preprocessor or preprocessor replacement Tischbein Programming 3 02-11-2007 11:38 AM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 06:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration