zoukankan      html  css  js  c++  java
  • Detecting Underlying Linux Distro

    If you are the owner of the system, then you know which Linux is installed and running. This article will help you to understand how to determine which Linux distribution is installed. You can incorporate this into your application to detect Linux distro.

    System Command: uname

    Most of the Linux systems provide uname to detect system released information.

    Release Information File

    Most of the Linux distributions maintain release information file in an/etc/directory. Here is the list of files on some of the well known Linux distributions:

    Novell SUSE /etc/SUSE-release
    Red Hat /etc/redhat-release, /etc/redhat_version
    Fedora /etc/fedora-release
    Slackware /etc/slackware-release, /etc/slackware-version
    Debian /etc/debian_release, /etc/debian_version,
    Mandrake /etc/mandrake-release
    Yellow dog /etc/yellowdog-release
    Sun JDS /etc/sun-release
    Solaris/Sparc /etc/release
    Gentoo /etc/gentoo-release
    UnitedLinux /etc/UnitedLinux-release
    ubuntu /etc/lsb-release

    Sample Script

    Using system command uname and contents of the release files you can write scripts of programs to help your software to detect distribution.

    #!/bin/sh
    # Detects which OS and if it is Linux then it will detect which Linux Distribution.
    
    OS=`uname -s`
    REV=`uname -r`
    MACH=`uname -m`
    
    GetVersionFromFile()
    {
    	VERSION=`cat $1 | tr "
    " ' ' | sed s/.*VERSION.*= // `
    }
    
    if [ "${OS}" = "SunOS" ] ; then
    	OS=Solaris
    	ARCH=`uname -p`	
    	OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
    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 "
    " ' '| sed s/VERSION.*//`
    		REV=`cat /etc/SUSE-release | tr "
    " ' ' | 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 "
    " ' ' | sed s/VERSION.*//`]"
    	fi
    	
    	OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
    
    fi
    
    
    echo ${OSSTR}



    from http://www.novell.com/coolsolutions/feature/11251.html

  • 相关阅读:
    2015/11/2用Python写游戏,pygame入门(2):游戏中的事件和显示
    2015/11/1用Python写游戏,pygame入门(1):pygame的安装
    2015/10/13 算法习题:最大子列和问题
    2015/10/9 Python核编初级部分学习总结
    2015/10/9 Python基础(21):可调用和可执行对象
    2015/9/29 Python基础(20):类的授权
    2015/9/28 Python基础(19):类的定制和私有性
    2015/9/22 Python基础(18):组合、派生和继承
    2015/9/21 Python基础(17):绑定和方法调用
    MVC 依赖注入
  • 原文地址:https://www.cnblogs.com/kex1n/p/6595831.html
Copyright © 2011-2022 走看看