Created
March 28, 2014 04:07
-
-
Save leolovenet/9825167 to your computer and use it in GitHub Desktop.
一个检测 Linux 服务器硬件资源脚本,包含服务器的型号,U 数,Dell 序列号,内存数,最大内存数,可以插的内存条数,已经用的内存条数,内存类型,硬盘大小,CPU 信息. A Linux server hardware detection resource script that contains the server model, U number, Dell serial number, the number of memory, the maximum amount of memory, the memory can be inserted in the number, the number of memory has been used, the type of memo…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ISINSTALLED_D=$(rpm -qa |grep dmidecode) | |
if [ -z $ISINSTALLED_D ]; then | |
yum -y install dmidecode | |
fi | |
export PATH=$HOME/bin:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin | |
NUM=$1 | |
NUM=${NUM:=0} | |
ISSHOW_DES=$2 | |
ISSHOW_DES=${ISSHOW_DES:=0} | |
U_NUM=$(dmidecode -t chassis |grep Height:|cut -d : -f 2) | |
U_NUM=${U_NUM// /} | |
PRODUCT=$(dmidecode -t system|grep Product|cut -d : -f 2| sed -e 's/^[ \t]*//') | |
SERIAL=$(dmidecode -t system|grep Serial|cut -d : -f 2| sed -e 's/^[ \t]*//') | |
HOSTNAME=$(hostname | cut -d . -f 1) | |
MEM=$(free -o|cut -c 1-20|grep -vi "swap"|grep Mem|cut -d : -f 2|sed -e 's/^[ \t]*//') | |
MEM=$(echo "$MEM 1000000" | awk '{printf "%.1fGB", $1/$2}') | |
MEM_MAX_CAPACITY=$(dmidecode -t memory|grep "Maximum Capacity"|cut -d : -f 2) | |
MEM_MAX_CAPACITY=${MEM_MAX_CAPACITY// /} | |
MEM_NUM_OF_DEV=$(dmidecode -t memory|grep "Number Of Devices"|cut -d : -f 2) | |
MEM_NUM_OF_DEV=${MEM_NUM_OF_DEV// /} | |
MEM_NUM_OF_DEV_USED=$(dmidecode -t memory|grep "Speed: Unknown"|wc -l) | |
MEM_NUM_OF_DEV_USED=$(($MEM_NUM_OF_DEV - $MEM_NUM_OF_DEV_USED)) | |
MEM_TYPE=$(dmidecode -t memory|grep "Type: "|tail -1|cut -d : -f 2) | |
MEM_TYPE=${MEM_TYPE// /} | |
DISK_SIZE=$(fdisk -l 2>/dev/null | grep GB |cut -d , -f 1|cut -d : -f 2|sed -e 's/ //g') | |
DISK_SIZE=$(echo $DISK_SIZE|tr ' ' '+') | |
CPU=$(cat /proc/cpuinfo |grep CPU|head -1|cut -d : -f 2 | sed -e 's/^[ \t]*//') | |
CPU=${CPU// /} | |
CPU=${CPU//@/ } | |
CPU_NUM=$(cat /proc/cpuinfo |grep CPU|wc -l) | |
CPU_INFO="$CPU * $CPU_NUM" | |
if [ "${ISSHOW_DES}0" != "00" ]; then | |
echo "|ID|服务器名|服务器型号|U数|DELL序列号|内存数|最大内存|总内存槽数|已经内存槽数|内存类型|硬盘大小信息|CPU 信息汇总|" | |
echo "|--|------|--------|---|---------|-----|------|---------|----------|------|----------|----------|" | |
fi | |
echo "|$NUM|$HOSTNAME|$PRODUCT|$U_NUM|$SERIAL|$MEM|$MEM_MAX_CAPACITY|$MEM_NUM_OF_DEV|$MEM_NUM_OF_DEV_USED|$MEM_TYPE|$DISK_SIZE|$CPU_INFO|" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
输出格式是 markdown 的 table