服务器硬件信息获取

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享

免费资源网 – https://freexyz.cn/

因项目需要需统计服务器设备型号/SN序列号/CPU型号/硬盘序列号等信息.

查询服务器基础信息 服务器硬件信息

查看服务器序列号及服务器型号

sudo dmidecode –s system-serial-number sudo dmidecode –s system-product-name CPU相关信息

获取CPU型号及CPU数量

awk -F: /model name/ {print $2} /proc/cpuinfo |sort |uniq awk -F: /physical id/ {print$2} /proc/cpuinfo |sort |uniq |wc -l 内存相关信息

获取内存大小及数量

sudo dmidecode -t memory |egrep ^[[:space:]]Size: |egrep -v Unknown|No |awk {i+=1}END{print “Mem Info: “$2“GB * “i} 磁盘相关信息

通过megacli查看硬件RAID磁盘类型及数量

sudo megaclisas-status |awk -F| /[/ {print $2$4} |sort|uniq -c

通过脚本获取详细数量及序列号

#!/bin/bash # 获取RAID磁盘信息 By:admin@ym68.cc # Date: 2021-04-08 # 获取磁盘硬件型号信息 Disk_Info=`sudo megacli -PDList -aALL |awk -F: /^Inquiry Data:/ {print $2}` # 获取磁盘空间信息 Disk_Size_Info=`sudo megacli -PDList -aALL |awk /^Coerced Size:/ {print $3,$4}` # 获取磁盘接口类型 Disk_PD_Type_Info=`sudo megacli -PDList -aALL |awk /^PD Type:/ {print $3}` # 获取磁盘属性Disk_Media_Type_Info=`sudo megacli -PDList -aALL |awk/^Media Type:/ {print $3}` Disk_Num=1 Disk_D_Sum=1 Disk_Model_D=“” IFS=$n for Disk_Type in ${Disk_Info};do Disk_Size=`echo ${Disk_Size_Info} | awk “NR==${Disk_Num} {print \$0}”` # 存储容量 Disk_Size_D=`echo ${Disk_Size}|awk {print $1}` # 存储容量类型 Disk_Size_Type=`echo ${Disk_Size}|awk {print $2}` if [ ${Disk_Size_Type} = TB ];thenDisk_Size_A_Info=`echo ${Disk_Size_D}|awk {print $1*1024*1024*1024*1024/1000/1000/1000/1000}` if [ “$[${Disk_Size_D: -1}%2]” -eq 0 ];then Disk_Size_A=`echo ${Disk_Size_A_Info} |head -c 4|awk {print $1}` else Disk_Size_A=`echo ${Disk_Size_A_Info} |head -c 4|awk {print $1+0.01}` fi elif [ ${Disk_Size_Type} = GB ];thenDisk_Size_A_Info=`echo ${Disk_Size_D}|awk {print $1*1024*1024*1024/1000/1000/1000}` if [ “$[${Disk_Size_D: -1}%2]”-eq 0 ];then Disk_Size_A=`echo ${Disk_Size_A_Info} |head -c 5|awk {print $1+0.5}` else Disk_Size_A=`echo ${Disk_Size_A_Info} |head -c 5|awk {print $1+1.1}` fi fi Disk_PD_Type=`echo ${Disk_PD_Type_Info} | awk “NR==${Disk_Num} {print \$0}”` Disk_Media_Type=`echo ${Disk_Media_Type_Info} | awk “NR==${Disk_Num} {print \$0}”` if [ ${Disk_Media_Type} = Hard ];then Disk_Media_Type=HDD elif [ ${Disk_Media_Type} = Solid ];then Disk_Media_Type=SSD else echo “获取设备属性失败!” fi if [[ ${Disk_Type} =~ “SAMSUNG” ]];then if [ ${Disk_Model_D} != “SAMSUNG” ];then Disk_D_Sum=1 fi Disk_Model=`echo ${Disk_Type} |awk {print $1}` Disk_Model_D=“SAMSUNG” elif [[ ${Disk_Type} =~ Intel ]];then if [ ${Disk_Model_D} != “INTEL” ];then Disk_D_Sum=1 fiDisk_Model=`echo ${Disk_Type} |awk {print $1}` Disk_Model_D=“INTEL” elif [[ ${Disk_Type} =~ “SEAGATE” ]];then if [ ${Disk_Model_D} != “SEAGATE” ];then Disk_D_Sum=1 fi Disk_Model=`echo ${Disk_Type} |awk {print $3}` Disk_Model_D=“SEAGATE” elif [[ ${Disk_Type} =~ “T010” ]];then if [ ${Disk_Model_D} != “T010”];then Disk_D_Sum=1 fi Disk_Model=`echo ${Disk_Type} |awk {print $1}` Disk_Model_D=“T010” elif [[ ${Disk_Type} =~ “ZR09RP41” ]];then if [ ${Disk_Model_D} != “ZR09RP41” ];then Disk_D_Sum=1 fi Disk_Model=`echo ${Disk_Type} |awk {print $1}` Disk_Model_D=“ZR09RP41” else echo “获取磁盘序列号失败!” fi echo ${Disk_D_Sum} ${Disk_Model} ${Disk_Media_Type} ${Disk_Size} Row ${Disk_Size_A} ${Disk_Size_Type} let Disk_D_Sum++ letDisk_Num++done

转自:https://www.ym68.cc/linux/2021/225158.html

免费资源网 – https://freexyz.cn/


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞8 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容