Sponsored Content
Top Forums Shell Programming and Scripting How to know which Linux Distribution i am using ? Post 302211858 by nobo on Friday 4th of July 2008 07:24:51 PM
Old 07-04-2008
whichNix

Found this old thread while researching. I come up against this problem often in a very heterogeneous network I admin. Barring us deploying Puppet or a similar solution (someday), I need a fix. There is no canonical way to determine distro so this script is a hack around. It works (gives a best guess) on slack, suse, rh, centOS, ubuntu, solaris, and a couple of other proprietary systems we use.

Comment, suggest, port, test, change, flame. Smilie
Code:
#! /bin/bash
# return an awkable string consisting of
#    unix OS type, or
#    Linux dist, or
#    a long guess (based on /proc), or
#    no clue

giveUp () {
   echo "Unknown"
   exit 0
}

# keep this easily awkable, prepending an initial clue
versionGuess () {
   if [ -e /proc/version ]; then
      echo -n "Unsure "
      cat /proc/version
      exit 0
   fi
   return 1
}

# if we have ignition, print and exit
gotDist () {
   [ -n "$1" ] && echo "$1" && exit 0
}

# we are only interested in a single word "dist" here
# various malformations can occur; admin will have to code appropately based on output
linuxRelease () {
   if [ -r /etc/lsb-release ]; then
      dist=$(grep 'DISTRIB_ID' /etc/lsb-release | sed 's/DISTRIB_ID=//' | head -1)
      gotDist "$dist"
   fi

   dist=$(find /etc/ -maxdepth 1 -name '*release' 2> /dev/null | sed 's/\/etc\///' | sed 's/-release//' | head -1)
   gotDist "$dist"

   dist=$(find /etc/ -maxdepth 1 -name '*version' 2> /dev/null | sed 's/\/etc\///' | sed 's/-version//' | head -1)
   gotDist "$dist"

   return 1
}

# start with uname and branch the decision from there
dist=$(uname -s 2> /dev/null)
if [ "$dist" = "Linux" ]; then
   linuxRelease
   versionGuess
   giveUp
elif [ -n "$dist" ]; then
   echo "$dist"
   exit 0
else
   versionGuess
   giveUp
fi

# we shouldn't get here
giveUp
# done

 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to know which Linux Distribution i am using

Hi, I m working on many Linux servers in my project. But i am unable to know which Linux Distribution i am using Like whether i am using SUSE or REDHAT or MONDRAKE. I tried with "uname" command. But it does not help me. Please provide me the command if u know. Regards, Basavaraja KC (3 Replies)
Discussion started by: BasavarajaKC
3 Replies

2. UNIX for Dummies Questions & Answers

What Linux distribution should I use?

Hey I am right now working on an old Compaq computer, and because I have a newer one I thought of installing Linux on this one. The thing is that I don't know which Linux distribution that would work with a minimum of lag. My computer specifications is: Compaq Presario 7000 Intel Pentium... (7 Replies)
Discussion started by: Sixmax
7 Replies

3. Programming

Linux Distribution

Hi, Can anyone please tell me, what is the best Linux distribution for Software Development. Thanks, Philip. (4 Replies)
Discussion started by: Phi01
4 Replies

4. Linux

which linux distribution to use for SOHO ?

Hi I consider changing operating system onto Linux. But I'm not sure what kind of distribution should I use : - Red Hat - Suse - Ubuntu - Debian - Fedora Operating system will be operating on the notebook to replace Win XP and must be stable version with all drivers to hardware (WiFi... (7 Replies)
Discussion started by: presul
7 Replies

5. Linux

What linux distribution is good?

Dear all i am new to Linux, i need a Linux OS that have been "qt development and lesstif" together. Regards (5 Replies)
Discussion started by: mkhorami76
5 Replies

6. Fedora

Starting out, Linux Distribution

Hi, i'm currently part of an apprenticeship becoming a IT specialist. Because I'm already an electronic technician (finished apprenticeship) I can do this one in 2 years (normally you need 3). Thing is, in school they started out with basic unix stuff (working with the shell) in the first... (3 Replies)
Discussion started by: Dr. Nick
3 Replies

7. What is on Your Mind?

What was your first Linux distribution?

What was the first Linux distribution you tried? My first was Knoppix, it was pretty good I thought, and it supported my old hardware http://www.linuxforum.com/images/smilies/smile.png Too bad I couldn't figure out how to install it at the time though. What about you? (32 Replies)
Discussion started by: billcrosby
32 Replies
CPANPLUS::Dist(3)					User Contributed Perl Documentation					 CPANPLUS::Dist(3)

NAME
CPANPLUS::Dist - base class for plugins SYNOPSIS
my $dist = CPANPLUS::Dist::YOUR_DIST_TYPE_HERE->new( module => $modobj, ); DESCRIPTION
"CPANPLUS::Dist" is a base class for "CPANPLUS::Dist::MM" and "CPANPLUS::Dist::Build". Developers of other "CPANPLUS::Dist::*" plugins should look at "CPANPLUS::Dist::Base". ACCESSORS
parent() Returns the "CPANPLUS::Module" object that parented this object. status() Returns the "Object::Accessor" object that keeps the status for this module. STATUS ACCESSORS
All accessors can be accessed as follows: $deb->status->ACCESSOR created() Boolean indicating whether the dist was created successfully. Explicitly set to 0 when failed, so a value of "undef" may be interpreted as "not yet attempted". installed() Boolean indicating whether the dist was installed successfully. Explicitly set to 0 when failed, so a value of "undef" may be interpreted as "not yet attempted". uninstalled() Boolean indicating whether the dist was uninstalled successfully. Explicitly set to 0 when failed, so a value of "undef" may be interpreted as "not yet attempted". dist() The location of the final distribution. This may be a file or directory, depending on how your distribution plug in of choice works. This will be set upon a successful create. $dist = CPANPLUS::Dist::YOUR_DIST_TYPE_HERE->new( module => MODOBJ ); Create a new "CPANPLUS::Dist::YOUR_DIST_TYPE_HERE" object based on the provided "MODOBJ". *** DEPRECATED *** The optional argument "format" is used to indicate what type of dist you would like to create (like "CPANPLUS::Dist::MM" or "CPANPLUS::Dist::Build" and so on ). "CPANPLUS::Dist->new" is exclusively meant as a method to be inherited by "CPANPLUS::Dist::MM|Build". Returns a "CPANPLUS::Dist::YOUR_DIST_TYPE_HERE" object on success and false on failure. @dists = CPANPLUS::Dist->dist_types; Returns a list of the CPANPLUS::Dist::* classes available $bool = CPANPLUS::Dist->rescan_dist_types; Rescans @INC for available dist types. Useful if you've installed new "CPANPLUS::Dist::*" classes and want to make them available to the current process. $bool = CPANPLUS::Dist->has_dist_type( $type ) Returns true if distribution type $type is loaded/supported. $bool = $dist->prereq_satisfied( modobj => $modobj, version => $version_spec ) Returns true if this prereq is satisfied. Returns false if it's not. Also issues an error if it seems "unsatisfiable," i.e. if it can't be found on CPAN or the latest CPAN version doesn't satisfy it. $configure_requires = $dist->find_configure_requires( [file => /path/to/META.yml] ) Reads the configure_requires for this distribution from the META.yml or META.json file in the root directory and returns a hashref with module names and versions required. $bool = $dist->_resolve_prereqs( ... ) Makes sure prerequisites are resolved format The dist class to use to make the prereqs (ie. CPANPLUS::Dist::MM) prereqs Hash of the prerequisite modules and their versions target What to do with the prereqs. create => Just build them install => Install them ignore => Ignore them prereq_build If true, always build the prereqs even if already resolved verbose Be verbose force Force the prereq to be built, even if already resolved perl v5.16.3 2013-05-20 CPANPLUS::Dist(3)
All times are GMT -4. The time now is 02:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy