Chris
Chris

Reputation: 456

Need to get Linux Dist name from different Dists

want to code a script that is for multiple linux distributions. Also want to add commands that check, and if not exist install some packages.. So, need a solution to ckeck Dist name (like Debian or RedHat) to execute the right command for this Dist. I have tryed "lsb_release" but is this working all the follow dists? : Debian / Ubuntu | Red Hat / Fedora / Suse / Cent OS" If yes, any idea where i can get the lsb_release output from all the Dists above?

in Debian I get this from lsb_release -a 2>/dev/null | grep Distributor:

Distributor ID: Debian

at Rasberry, I get this:

Distributor ID: Raspbian

but what about other Distributions?

Upvotes: 0

Views: 313

Answers (2)

GAD3R
GAD3R

Reputation: 4625

Yes, the lsb_release should print the distribution information after installing the required package.

e,g:

On debian based distro:

apt-get install lsb-release

On RHEL based distro:

yum install redhat-lsb-core

or

yum install redhat-lsb

Alernative method : You can get the distribution information through:

On debian based disto

cat /proc/version
cat /etc/issue
cat /etc/issue.net
cat /etc/lsb-release
cat /etc/os-release

On RHEL based distro :

cat /proc/version
cat /etc/centos-release
cat /etc/lsb-release
cat /etc/redhat-release
cat /etc/system-release

Upvotes: 1

Vadim Ponomarev
Vadim Ponomarev

Reputation: 96

seems that all modern linux distributions have /etc/os-release file with ID=distribution (unfortunately have no Raspberry around to test).

Upvotes: 1

Related Questions