openSUSE Forums > Programming/Scripting » How do I get distro-info

Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
Page 2 of 2 1 2
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 06-Nov-2009, 07:04
hcvv's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: Netherlands
Posts: 1,911
hcvv 's reputation will be famous soon enoughhcvv 's reputation will be famous soon enoughhcvv 's reputation will be famous soon enough
Default Re: How do I get distro-info

Quote:
Originally Posted by freefox View Post
I tried to illustrate that with my psedo code block.
Depending on distro I would like different things to execute.
That was perfectly clear to most of us.

About the 'generic' solution. As there is almost no standard, there may be no 'generic' solution. A test on existence of e.g. /etc/SuSE-release and likewise for every taste you know about might be needed. I do know that (at least some years ago) there was /etc/redhat-release. Which shows that upper/lower case is also not handled the same by everyone.

The lsb_release (see man page) seems to follow the LSB and as such is likely to be more widely available.

When your 'generic' also involves Unix tastes, a test on uname -s will give you a first triage.
__________________
Henk van Velden
Reply With Quote
  #12 (permalink)  
Old 06-Nov-2009, 12:41
Global Moderator
 
Join Date: Jul 2008
Location: Salt Lake City, Utah
Posts: 1,252
hendersj 's reputation will be famous soon enoughhendersj 's reputation will be famous soon enoughhendersj 's reputation will be famous soon enough
Default Re: How do I get distro-info

On Fri, 06 Nov 2009 09:56:01 +0000, TaraIkeda wrote:

> Well why use commandline when both Ubuntu and openSUSE offer a gui to
> identify the version?


Probably because the OP's writing a script and GUIs are notoriously bad
for inclusions in scripts used to automate things. ;-)

Jim

--
Jim Henderson
openSUSE Forums Moderator
Reply With Quote
  #13 (permalink)  
Old 06-Nov-2009, 13:41
cjcox's Avatar
Parent Penguin
 
Join Date: Jun 2008
Location: Frisco, TX
Posts: 778
cjcox hasn't been rated much yet
Default Re: How do I get distro-info

On Fri, 2009-11-06 at 09:36 +0000, freefox wrote:
> Are there some command line tool that shows distro and version of
> distro?
>
> I would like to
>
> Code:
> --------------------
> #!/whatever shell
> if (opensuse)
> # stuff
> elseif (ubuntu)
> # other stuff
> endif
> --------------------
>
>

Code:
vers=`cat /etc/*elease`
if echo "$vers" | grep 'openSUSE' >/dev/null 2>&1; then
ostype="OpenSUSE"
elif echo "$vers" | grep 'SUSE' >/dev/null 2>&1; then
ostype="SUSE"
elif echo "$vers" | grep 'Red Hat' >/dev/null 2>&1; then
ostype="Red-Hat"
elif echo "$vers" | grep 'Fedora' >/dev/null 2>&1; then
ostype="Fedora"
elif echo "$vers" | grep 'Ubuntu' >/dev/null 2>&1; then
ostype="Ubuntu"
elif echo "$vers" | grep 'CentOS' >/dev/null 2>&1; then
ostype="CentOS"
fi

Reply With Quote
  #14 (permalink)  
Old 06-Nov-2009, 13:59
hcvv's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: Netherlands
Posts: 1,911
hcvv 's reputation will be famous soon enoughhcvv 's reputation will be famous soon enoughhcvv 's reputation will be famous soon enough
Default Re: How do I get distro-info

I like
Code:
grep -i 'openSUSE';
instead of
Code:
grep 'openSUSE' >/dev/null 2>&1;
And you could make it into a loop
Code:
for string in 'openSUSE' 'SUSE' ...
do
done
Easy to expand with a new distribution then.
__________________
Henk van Velden
Reply With Quote
  #15 (permalink)  
Old 06-Nov-2009, 16:04
Student Penguin
 
Join Date: Jun 2008
Posts: 66
tcubed_bus hasn't been rated much yet
Default Re: How do I get distro-info

Code:
dmesg | grep -i "linux version"
Plus a bit more parsing...
Reply With Quote
  #16 (permalink)  
Old 07-Nov-2009, 03:45
hcvv's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: Netherlands
Posts: 1,911
hcvv 's reputation will be famous soon enoughhcvv 's reputation will be famous soon enoughhcvv 's reputation will be famous soon enough
Default Re: How do I get distro-info

Quote:
Originally Posted by hcvv View Post
I like
Code:
grep -i 'openSUSE';
instead of
Code:
grep 'openSUSE' >/dev/null 2>&1;
For those thinking I am talking nuts here, they are correct.
I wanted to use the -q option to avoid any output and thus avoid to redirect it to /dev/null
Code:
grep -q
leaves you with the return code only and that is what we want here.
__________________
Henk van Velden
Reply With Quote
  #17 (permalink)  
Old 07-Nov-2009, 15:20
Puzzled Penguin
 
Join Date: Aug 2009
Location: Värmland, Sweden
Posts: 21
freefox hasn't been rated much yet
Smile Re: How do I get distro-info (solved)

Thanks a lot to all of you.
Now I've got what I need.

/freefox
__________________
| openSUSE 11.2 | gnome | laptop: asus x5dij | intel core 2 duo t5900 | 64 bit | screen: 15,6" WXGA Glare LED (1366x768) | graphic: Intel GMA 4500 | HSDPA USB modem - HUAWEI E220 |
Reply With Quote
  #18 (permalink)  
Old 07-Nov-2009, 20:55
caf4926's Avatar
Global Moderator
 
Join Date: Jun 2008
Location: The English Lake District. UK - GMT/BST
Posts: 12,934
caf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputationcaf4926 has a brilliant future with this reputation
Send a message via MSN to caf4926
Default Re: How do I get distro-info

kernelcruncher@openSUSE-11:~> cat /etc/SuSE-release
openSUSE 11.2 (i586)
VERSION = 11.2
kernelcruncher@openSUSE-11:~>
__________________
Box: openSUSE 11.2 | (KDE4.3.3) | M2N4-SLI | AMD 64 X2 5200+ | nVidia 8500GT | 4GB RAM
Lap: openSUSE 11.2 | Celeron 550 | (KDE4.3.3)"3" | Intel 965 GM | Lenovo R61e | 3GB RAM
Reply With Quote
Reply
Page 2 of 2 1 2

Bookmarks


Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2