Are there some command line tool that shows distro and version of distro?
I would like to
#!/whatever shell
if (opensuse)
# stuff
elseif (ubuntu)
# other stuff
endif
Are there some command line tool that shows distro and version of distro?
I would like to
#!/whatever shell
if (opensuse)
# stuff
elseif (ubuntu)
# other stuff
endif
Well why use commandline when both Ubuntu and openSUSE offer a gui to identify the version?
cat /etc/SuSE-release
will display you the architecture and the version.
smweb@boven:~> cat /etc/SuSE-release
openSUSE 10.3 (i586)
VERSION = 10.3
smweb@boven:~>
And how is he suposed to use that information in the rest of his script?
I tried to illustrate that with my psedo code block.
Depending on distro I would like different things to execute.
Thanks. That solves the suse part. But I would like a more generic solution, telling which distro it is too. suse or ubuntu or …
More ideas, please.
Not sure there is a more generic though neither am I sure you can just rely on this. cat /etc/*-release really should work but what if for some reason it is empty? Any way this has some and has a few suggestions at some wildcards that may catch most.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
If the aforementioned file exists, then SUSE. If not, then test for
something Ubuntu-specific. What that is, though, is probably something to
be found in an Ubuntu forum. A quick Google search as follows:
ubuntu version command line
turned up several hits that answered the question (cat /etc/issue
) which
also works on my SUSE box so maybe that is a better distribution-agnostic
way to get which distro you are on.
Good luck.
freefox wrote:
> Thanks. That solves the suse part. But I would like a more generic
> solution, telling which distro it is too. suse or ubuntu or …
>
> More ideas, please.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBAgAGBQJK9BdsAAoJEF+XTK08PnB5xqAP+QGn7fG/1F3j4t9FQrRw60yL
CPXizU9whWYICqGbqtfVoKq/F8LN1yv4+2JAwL5vtsVHJZwTZts2oOCDI3ddRZ50
mZuKkFTeTXCWjlsQA1HPvI7I03MZpy69s0Qxsm1Eo8lBIIh/IS2q2fkWuWKnObjt
CVNGB317iW0aAato69BfRrMuQcGNfKwMKrnrk9lgo5HRWjOPTpbDwk3QEEYFpv4x
oE1j+fZ3xDnGjB7p/VIhHjxVA+hYnk3NL/CGAkz2jlvSfSkHp8DQDK2x1M6omgyB
+5yG4xBR+ahMh4PIsuv+xHIOxqtoUWT2AvuEnSMJkW74vz+c3LE2E6/J7qrE+Oaa
+GvLh92CaYFYjd3ypxVN9WsNQaqUGfMDjhukHbuZTW6gTXIjKn+Lyu1B3efYdQyo
9LDE6HyRe3uVCTguTDLh/1TG8IgiqfYrKs3o+IYORqUirgyT2+mtXAR86pO6LOv0
vz6mXrTSG5+e66QPyf605AeOSIwmOhZXFL7N0A0ZAWwsBNND82NlnS6b+0mMS98/
hNJsfyfYHIfQN4j2HX6DcNKiPNw/EtXtvhN7ipuK9kEMc7+4/wEOaTS7/qnXMjm7
hHkZDHydaeTnJWmlA1bH009L/2ZFj6e9/mp8sx1+5lqUNTIiJfwuPo5rm8Eyxbab
QnL+1HocqXZOTAZUikqF
=gq5k
-----END PGP SIGNATURE-----
Hi
Use the lsb_release command eg in my sig I use;
MYSYSTEM=`lsb_release -sd |cut -f2 -d ""\"`
–
Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.27.37-0.1-default
up 3 days 9:12, 2 users, load average: 0.03, 0.09, 0.05
GPU GeForce 8600 GTS Silent - CUDA Driver Version: 190.18
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.
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
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
> --------------------
>
>
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
I like
grep -i 'openSUSE';
instead of
grep 'openSUSE' >/dev/null 2>&1;
And you could make it into a loop
for string in 'openSUSE' 'SUSE' ...
do
done
Easy to expand with a new distribution then.
dmesg | grep -i "linux version"
Plus a bit more parsing…
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
grep -q
leaves you with the return code only and that is what we want here.
Thanks a lot to all of you.
Now I’ve got what I need.
/freefox
kernelcruncher@openSUSE-11:~> cat /etc/SuSE-release
openSUSE 11.2 (i586)
VERSION = 11.2
kernelcruncher@openSUSE-11:~>;)