linux平台名称,在Unix/Linux平台上找到os名称和版本的最佳方式

这适用于所有Linux环境。

#!/bin/sh

cat /etc/*-release

在Ubuntu中:

$ cat /etc/*-release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=10.04

DISTRIB_CODENAME=lucid

DISTRIB_DESCRIPTION="Ubuntu 10.04.4 LTS"

或12.04:

$ cat /etc/*-release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=12.04

DISTRIB_CODENAME=precise

DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"

NAME="Ubuntu"

VERSION="12.04.4 LTS,Precise Pangolin"

ID=ubuntu

ID_LIKE=debian

PRETTY_NAME="Ubuntu precise (12.04.4 LTS)"

VERSION_ID="12.04"

在RHEL中:

$ cat /etc/*-release

Red Hat Enterprise Linux Server release 6.5 (Santiago)

Red Hat Enterprise Linux Server release 6.5 (Santiago)

或使用此脚本:

#!/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 "\n" ' ' | 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 "\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

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

fi

echo ${OSSTR}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值