shell脚本查看服务器基本信息

 1 #!/bin/sh 
 2 #电脑概览
 3 #电脑型号
 4 ComputerModel=`/usr/bin/sudo /usr/sbin/dmidecode | grep -A2 "System Information" | awk -F ':' '{print $2}' | grep -v '^$' |sed -e 's/Inc//g' -e 's/ //g' -e ':a;N;s/\n/ /g;ta' -e 's/.//g'`
 5 x86_64=`getconf LONG_BIT`
 6 #系统版本
 7 SystemVersion=`cat /etc/redhat-release`
 8 #内核版本
 9 KernelVersion=`uname -r`
10 #CPU信息,1物理CPU个数2,查看每个物理CPU中core的个数(即核数)3,查看逻辑CPU的个数(即线程)4.CPU型号
11 CPUNum=`cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l`
12 CPUNucleusNum=`cat /proc/cpuinfo| grep "cpu cores"| uniq | awk -F ':' '{print $2}' | sed 's/ //g'`
13 CPUThreadNum=`cat /proc/cpuinfo| grep "processor"| wc -l`
14 CPUmodel=`cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq | sed 's/ //g'`
15 CPUTotalnuclearNum=$[$CPUNum*$CPUNucleusNum]
16 #主板型号,1.主板厂商与型号,2.主板版本
17 MotherBoardModel=`/usr/bin/sudo /usr/sbin/dmidecode | grep -A2 "Base Board Information$" | awk -F ':' '{print $2}' | grep -v '^$' |sed -e 's/Inc//g' -e 's/ //g' -e ':a;N;s/\n/ /g;ta' -e 's/.//g'`
18 MotherBoardVersion=`/usr/bin/sudo /usr/sbin/dmidecode | grep -A3 "Base Board Information$" | awk -F ':' '{print $2}' | grep -v '^$' |sed -e 's/Inc//g' -e 's/ //g' -e ':a;N;s/\n/ /g;ta' -e 's/.//g' | awk '{print $3}'`
19 #内存,1.内存总数2,内存插槽编号,3内存规格,4内存数组,5.循环出所有的内存条参数,6内存显示,7内存数量,8总插槽数量,9支持最大内存
20 MemoryNum=`/usr/bin/sudo /usr/sbin/dmidecode -t memory | grep Size | awk '{print $2}' | grep -v 'No' | awk '{sum +=$1};END{print sum/1024}'`
21 MemoryName=`/usr/bin/sudo /usr/sbin/dmidecode -t memory | grep '^Handle' | awk '{print $2}' | sed 's/,//g'`
22 MemoryNameDDR=""
23 MemoryArray=0
24 for i in ${MemoryName[@]}
25 do
26     Memorytest=`/usr/bin/sudo /usr/sbin/dmidecode -t memory | grep -A19 '^Handle '$i'' | grep -E 'Configured Clock Speed|Speed' | grep 'Unknown'`
27     if [ $? -eq 0 ];then
28         continue
29     fi
30     MemoryNameDDR[$MemoryArray]=`/usr/bin/sudo /usr/sbin/dmidecode -t memory | grep -A19 '^Handle '$i'' | grep -E 'Type|Configured Clock Speed|Speed' | grep -Ev 'Error|Unknown' | awk -F ':' '{print $2}' | sed -e '2{h;d};3G' | sed -e ':a;N;s/\n/ /g;ta' | awk '{for(i=4;i<=NF;++i) printf $i " ";print $1,$2,$3,"\n"}'`
31     let MemoryArray=MemoryArray+1
32 done
33 MemoryEcho=`echo ${MemoryNameDDR[*]} | sed -e 's/MHz/MHz\n/g' | sed -e 's#^ ##g' | sort -r | uniq |grep -v '^$'`
34 Memory=`/usr/bin/sudo /usr/sbin/dmidecode -t memory | grep -E Size | grep -Ev  'Installed Size|Maximum Memory Module Size|Maximum Total Memory Size:|Enabled Size:|No' | wc -l`
35 MemoryTotalSlotNum=`/usr/bin/sudo /usr/sbin/dmidecode -t memory | grep "Number Of Devices:" | awk -F':' '{print $2}' | sed 's/ //g'`
36 MemoryMaximumCapacity=`/usr/bin/sudo /usr/sbin/dmidecode -t memory | grep "Maximum Capacity:" | awk -F':' '{print $2}' | sed 's/ //g'`
37 #硬盘1,获取所有硬盘盘符,2,只获取第一块硬盘信息,3.储存判断信息,4获取服务器厂商名,5根据服务器厂商名获取磁盘厂商名
38 diskNum=`ls /dev/sd* | grep -v '[0-9]$' | awk -F '/' '{print $3}'`
39 diskVersion=`/usr/bin/sudo /usr/sbin/smartctl --all /dev/${diskNum[0]} | grep -E 'Vendor|Product|User Capacity|Rotation Rate' | grep -v 'cache' | awk -F ':' '{print $2}' | sed -e 's# ##g' -e 's/\[/[\n/g' -e 's#]##g' | sed -e '/\[/d' -e 's/rpm//g' | sed ':a;N;s/\n/ /g;ta' | awk '{print $1,$2,"("$3"/"$4"/分)"}'`
40 diskYes=""
41 diskComputerModel=`/usr/bin/sudo /usr/sbin/dmidecode | grep -A1 "System Information" | awk -F ':' '{print $2}' | grep -v '^$' |sed -e 's/Inc//g' -e 's/ //g' -e 's/,//g' | awk -F '.' '{print $1}' `
42 diskRAID=`cat /proc/scsi/scsi | grep Vendor | sed -e 's/Model/\nModel/g' | sed -e '/Model/d' | grep -Eo $diskComputerModel'|VMware'`
43 #diskSize=`fdisk -l | grep "Disk" | awk '{print $3}' | awk '{sum +=$1};END{print sum}'`
44 diskSize=`df -P | grep -v 'Filesystem' | awk '{sum +=$2};END{print sum/1024/1024}'`
45 if [ "$diskRAID" = "VMware" ];
46 then
47     diskYes='unknown(Because the hard drive is VMware)'
48 elif [ "$diskComputerModel" = "$diskRAID" ];
49 then
50     diskYes='Yes'
51 else
52     diskYes='No'
53 fi
54 #显卡
55 VGA=`/usr/bin/sudo /sbin/lspci |grep VGA | awk -F ':' '{print $3}' | awk -F '.' '{print $1$2}'| sed -e 's#^ ##g'`
56 #网卡
57 network=`/usr/bin/sudo /sbin/lspci | grep Ethernet | awk -F ':' '{print $3}' | uniq | sed 's/^ //g'`
58 #系统序列号
59 SystemSerialNum=`/usr/bin/sudo /usr/sbin/dmidecode -s system-serial-number`
60 #打印
61 echo -e "Server model"'\t'$ComputerModel
62 echo -e "serial number"'\t'$SystemSerialNum
63 echo -e "system version"'\t'$SystemVersion"X"$x86_64
64 echo -e "Kernel version"'\t'$KernelVersion
65 echo -e '\n'
66 echo -e "processor  "'\t'$CPUmodel"(*"$CPUNum") "$CPUTotalnuclearNum""
67 echo -e "Motherboard"'\t'$MotherBoardModel"("$MotherBoardVersion")"
68 echo -e "RAM    "'\t\t'$MemoryNum" GB"
69 echo -e "Total Slots"'\t'""$MemoryTotalSlotNum
70 echo -e "Used Slots"'\t'$Memory " Maximum memory support:"$MemoryMaximumCapacity
71 echo -e "Hard Details"'\t'"RAID:"$diskYes "capacity:"$diskSize"G"
72 echo -e "The first disk"'\t'$diskVersion
73 #echo -e "显卡    "'\t'$VGA
74 echo -e "NIC    "'\t\t'$network | sed 's/) [A-Z a-z 1-9]/)\n &/g' | sed -e 's/^ /\t\t/g' -e 's/\t) /\t/g' | grep -v '^$'

 

posted @ 2018-03-16 10:10  IT菜鸟园  阅读(2724)  评论(0编辑  收藏  举报