shell to get machine info

2010-11-29  张林 

#!/bin/sh
# small utility unix script for showing machine info
uname -a
case "`uname`" in
    HP-UX*)
       tmpfile=`mktemp`
       machinfo > $tmpfile
       grep "Number of CPUs" $tmpfile
       grep "Clock speed " $tmpfile
       grep "Memory" $tmpfile
       rm -f $tmpfile
       ;;
    SunOS*)
       tmpfile="/tmp/"`date '+info_%m%d%H%M%S'`
       mname=`uname -m`
       /usr/platform/${mname}/sbin/prtdiag -v > $tmpfile
       awk '/ CPUs/ { print $0 }' $tmpfile
       noc=`awk '/ CPUs / {
            while (getline) { if ($1=="---") break; } cpuCnt=0;
            getline;
            while (getline) { cpuCnt++; if (NF==0) break }
            print cpuCnt }' $tmpfile`
       echo "Number of CPUs " $noc
       grep "System clock frequency" $tmpfile
       grep "Memory size" $tmpfile
       rm -f $tmpfile
       ;;
    Linux*)
       cat /etc/redhat-release
       noc=`cat /proc/cpuinfo | grep '^processor' | wc -l`
       echo "Number of CPUs " $noc
       cat /proc/cpuinfo | grep '^cpu MHz' | head -1
       cat /proc/meminfo | grep '^MemTotal'
       ;;
    CYGWIN*)
       cygcheck -s  | grep -i '^window'
       noc=`cat /proc/cpuinfo | grep '^processor' | wc -l`
       echo "Number of CPUs " $noc
       cat /proc/cpuinfo | grep '^cpu MHz' | head -1
       cat /proc/meminfo | grep '^MemTotal'
esac

./info.sh
Linux ydcrh04 2.6.18-128.el5xen #1 SMP Wed Dec 17 12:01:40 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
Number of CPUs  4
cpu MHz         : 3000.190
MemTotal:      9908224 kB
[oracle@ydcrh04 monitor]$ uname -a
Linux ydcrh04 2.6.18-128.el5xen #1 SMP Wed Dec 17 12:01:40 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

./info.sh
Linux ydcrh07 2.6.18-164.el5xen #1 SMP Tue Aug 18 15:59:52 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
Number of CPUs  16
cpu MHz         : 2399.334
MemTotal:     16032768 kB

./info.sh
Linux ydcvml03 2.6.27.5-117.fc10.i686.PAE #1 SMP Tue Nov 18 12:08:10 EST 2008 i686 i686 i386 GNU/Linux
Fedora release 10 (Cambridge)
Number of CPUs  2
cpu MHz         : 3166.666
MemTotal:      3894612 kB



432°/4320 人阅读/0 条评论 发表评论

登录 后发表评论