Mencari tahu distribusi (distro) Linux box

| Wednesday, August 20, 2008

Sebenarnya udah agak lama aku nyari perintah di linux untuk mengetahui jenis ditro yang digunakan, karena beda dengan freebsd yg kalau di uname -a langsung deh kliatan freebsd versi brapa stable atau release dll. coba nih bandingkan

uname -a pada FreeBSD :

FreeBSD 6.2-RELEASE-p1 #0: Tue Feb 27 17:40:07 WIT 2007 root@gateway.net:/usr/src/sys/i386/compile/ROUTER i386


uname -a pada pada unknown linux box :

Linux cobanet 2.6.21.5-smp #2 SMP Tue Jun 19 14:58:11 CDT 2007 i686 Intel(R) Pentium(R) D CPU 2.66GHz GenuineIntel GNU/Linux

Nah kan.. bagi saya yang kurang familier dengan linux apalagi versi kernel2nya.. susah juga.

Setelah tanya sini situ, ternyata bisa dicoba dengan cara
# more /etc/issue

Tapi pada linux box yg saya test keluarnya gini :

root@cobanet:~# more /etc/issue
Welcome to \s \r (\l)

Saya masih penasaran, akhirnya googling dannnnn alhamdulillah ketemu scriptnya, ini nih scriptnya :

#!/bin/ksh

system=`uname -s| tr 'A-Z' 'a-z'`

cputype=`uname -m`

for rfile in \
SuSE-release \
redhat-release \
redhat_version \
gentoo-release \
fedora-release \
turbolinux-release \
mandrake-release \
mandrakelinux-release \
debian_version \
debian_release \
knoppix-version \
yellowdog-release \
slackware-version \
slackware-release \
conectiva-release \
mandriva-release \
immunix-release \
tinysofa-release \
trustix-release \
adamantix_version \
yoper-release \
arch-release \
libranet_version \
va-release \
; do
if [ -r /etc/$rfile ] ; then
distro=$(echo $rfile | \
tr 'A-Z' 'a-z' | \
sed -e 's/[_-]\(release\|version\)$//')
if [ "$distro" = "va" ] ; then distro=va-linux; fi
break
fi
done

case "$distro" in
suse)
if grep -q Enterprise /etc/SuSE-release ; then
release=SLES
version=$(egrep 'VERSION' /etc/SuSE-release | \
sed -e 's/ *VERSION *= *//')-pl$(egrep 'PATCHLEVEL' \
/etc/SuSE-release | sed -e 's/ *PATCHLEVEL *= *//')
else
release=SuSE
version=$(egrep 'VERSION' /etc/SuSE-release | \
sed -e 's/ *VERSION *= *//')
fi
;;
redhat)
# First part of red hat release is everything before 'release'
release=$(sed -e 's/ release.*$//' /etc/redhat-release | \
sed -e 's/[^A-Z]//g')
# Second part of red hat release is numbers after 'release'
version=$( sed -e 's/^.* release//' /etc/redhat-release | \
sed -e 's/[^0-9]//g' | \
sed -e 's/\([0-9]\)\([0-9]\)/\1.\2/g')
;;
esac

# CPU info from /proc/cpuinfo
set -A model_info \
$(grep 'model name' /proc/cpuinfo | \
uniq | \
tr 'A-Z' 'a-z' | \
perl -wn -e \
's/\s*model\s*name\s*:\s*//go; s/\((tm|r)\)//go; s/\s*(processor|cpu)//go; print;')
cpuvendor=${model_info[0]}
cpumodel=${model_info[1]}
cpuspeed=${model_info[2]}

# GLIBC info:
glibc=$(rpm -qv glibc|uniq)

printf "$system $cputype $cpumodel $distro $release-$version $glibc $cpuvendor $cpuspeed\n"

0 komentar: