Skip to content

Instantly share code, notes, and snippets.

@yangvipguang
Created June 1, 2018 07:35
Show Gist options
  • Save yangvipguang/ddce1a2184fd621c0df07b0e7a2fd8e1 to your computer and use it in GitHub Desktop.
Save yangvipguang/ddce1a2184fd621c0df07b0e7a2fd8e1 to your computer and use it in GitHub Desktop.
Linux Server—Info
# 服务器型号
dmidecode | grep "Product" > server.temp.info
serverModelInfo="服务器型号:"
while read lineStr
do
temp=`echo ${lineStr##*:}`
serverModelInfo="${serverModelInfo}${temp} "
done < server.temp.info
# 操作系统
os=`cat /etc/centos-release`
osInfo="操作系统:${os}"
# 处理器
cpuNameInfo=`cat /proc/cpuinfo | grep "model name" | uniq`
cpuCount=`cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l`
cpuCoreCount=`cat /proc/cpuinfo| grep "cpu cores"| uniq`
cpuCoreCount=`echo ${cpuCoreCount##*:}`
maxThreadCount=`cat /proc/cpuinfo |grep "processor"|wc -l`
cpuMHZ=`cat /proc/cpuinfo |grep MHz|uniq`
cpuBit=`getconf LONG_BIT`
cpuNameInfo=`echo ${cpuNameInfo##*:}`
cpuNameInfo="处理器:${cpuNameInfo}(${cpuCount}路${cpuCoreCount}核 最多${maxThreadCount}个线程 ${cpuBit}位处理器)"
# 主板
boradNameStr=`dmidecode -t 2 | grep "Product Name" | uniq`
boardName=`echo ${boradNameStr##*:}`
boardNameInfo="主板:${boardName}"
# 内存
# Memory
memStr=`dmidecode -t 17 | grep "Size:.*MB" | uniq`
memSizeStr=`echo ${memStr##*:}`
memSize=`echo ${memSizeStr} | tr -cd "[0-9]"`
memSizeInGB=`expr ${memSize} / 1024`
# MaxMemory
maxMemStr=`dmidecode -t 16 | grep Maximum | uniq`
maxMem=`echo ${maxMemStr##*:} | sed s/[[:space:]]//g`
memoryInfo="内存:${memSizeInGB}GB(最大内存${maxMem})"
# 硬盘
lsblk -o name,type,size,kname,fstype,MODEL,size | grep disk > server.temp.info
diskCountStr=`lsblk -o TYPE | grep -i disk | wc -l`
hardDiskInfo="硬盘:${diskCountStr}个硬盘 "
while read lineStr
do
arr=(${lineStr})
info="硬盘${arr[0]}(${arr[2]}) "
hardDiskInfo="${hardDiskInfo}${info} "
done < server.temp.info
# 网卡
networkNameStr=`lspci | grep Ethernet | uniq`
networkName=`echo ${networkNameStr##*:}`
networkNameInfo="网卡:${networkName}"
# 概况
serverTotal="\n ${serverModelInfo}\n ${osInfo}\n ${cpuNameInfo}\n ${boardNameInfo}\n ${memoryInfo}\n ${hardDiskInfo}\n ${networkNameInfo}\n"
echo -e "${serverTotal}" > GetServerInfo.txt
echo -e "${serverTotal}"
rm -f server.temp.info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment