Skip to content
Advertisement

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?

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement