Home arrow Scripting arrow Shell Scripts arrow DTRM: Determine what Linux/Unix distribution is running
DTRM: Determine what Linux/Unix distribution is running Print E-mail
Written by Jason   
Nov 07, 2008 at 11:23 AM

I recently ran into a Linux server that was very stripped down to the point where I was having problems figuring out what the underlying distribution was. Here's a script I found elsewhere and modified somewhat to determine what the distribution is.




Since the previous author didn't name it, I'm calling this script DTRM. Since I've found this useful I'm going to continue to update this and add more functionality, so check back occasionally.

#!/bin/sh
# DTRM - Tries to detects which OS and distribution.

OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`
UNM=`uname -a | awk '{print $2}'`

GetVersionFromFile()
{
        VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
}

if [ "${OS}" = "SunOS" ] ; then
        OS=Solaris
        ARCH=`uname -p`
        OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
        PSUEDONAME=`cat /etc/release`

elif [ "${OS}" = "HP-UX" ] ; then
        OS="Hewlett Packard UNIX (HP-UX)"
        MACH=`/usr/bin/model`
        OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"

elif [ "${OS}" = "AIX" ] ; then

        OSSTR="${OS} `oslevel` (`oslevel -r`)"

elif [ "${OS}" = "Linux" ] ; then
        KERNEL=`uname -r`

        if [ -f /etc/redhat-release ] ; then
                DIST='RedHat'
                PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
                REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`

        elif [ -f /etc/SUSE-release ] ; then
                DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
                REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`

        elif [ -f /etc/SuSE-release ] ; then
                DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
                REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`

        elif [ -f /etc/mandrake-release ] ; then
                DIST='Mandrake'
                PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
                REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`

        elif [ -f /etc/debian_version ] ; then
                DIST="Debian `cat /etc/debian_version`"
                REV=""
        fi

        if [ -f /etc/UnitedLinux-release ] ; then
                DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
        fi

        if [ "${UNM}" = "OpenWrt" ] ; then
                DIST="OpenWrt"
                PSUEDONAME="OpenWrt Embedded Linux - BusyBox"
                REV=""
        fi

        OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"

fi

echo ${OSSTR}

Last Updated ( Dec 08, 2008 at 08:27 AM )
� http://www.roboguys.com, Mambo and Designed by Siteground