LinuxQuestions.org
Review your favorite Linux distribution.
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, 05: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, 07:11 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,838

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
Simply check for the existence of /etc/redhat-release.
 
Old 07-23-2012, 11:00 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Code:
uname -a -m -p
 
Old 07-24-2012, 02: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, 02:29 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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, 04: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, 04:57 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
why do you want to differentiate? usually the same code will run on both.
 
Old 07-24-2012, 05: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, 05:36 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:28 AM
how to differentiate two versions of qt wagmare Linux - Newbie 6 03-09-2009 09: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 03:52 AM
C pre-preprocessor or preprocessor replacement Tischbein Programming 3 02-11-2007 12:38 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 07:45 AM


All times are GMT -5. The time now is 12:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration