na=`lsblk | grep disk | awk '{print $1}'`
for i in ${na[@]}
do
Current_Pending_Sector_valur=`smartctl -a /dev/$i | grep Current_Pending_Sector|awk '{print $6}'`
if [[ $Current_Pending_Sector_valur -lt 80 ]] ;then
echo $i is healthy
else
echo $i is unhealthy
fi
done
<NVME device on /dev/nvme2 mod:Samsung SSD 970 EVO Plus 2TB sn:dfdfdssdada323234>
####################################################################################
function lala() {
#scsi
na=`lsblk | grep disk | awk '{print $1}'|sort`
system_name=`dmidecode -t1 | grep 'Serial Number:' | awk '{print $3}'`
for i in ${na[@]}
do
DM=`smartctl -i /dev/$i | grep 'Device Model:'| awk '{print $3 $4}'`
SM=`smartctl -i /dev/$i | grep 'Serial Number:'| awk '{print $3}'`
FV=`smartctl -i /dev/$i | grep 'Firmware Version:'| awk '{print $3}'`
CP=`smartctl -i /dev/$i | grep 'User Capacity:'| awk '{print $5$6}'`
printf "<name=/dev/%s sys_name=%s dn=%s sn=%s mod=%s capability=%s>\n" $i $system_name $DM $SM $FV $CP
done
#nvme
nv=`lsblk |grep nvme | awk '{print $1}'`
for ((i=1;i<=2;i++))
do
DevicePath=`nvme list --output-format=json | grep DevicePath | awk -F '"' '{print $4}'|awk "NR==$i"`
SerialNumber=`nvme list --output-format=json |grep 'SerialNumber'| awk -F '"' '{print $4}'|awk "NR==$i"`
ModelNumber=`nvme list --output-format=json |grep 'ModelNumber'| awk -F '"' '{print $4}'|awk "NR==$i"`
Firmware=`nvme list --output-format=json |grep 'Firmware'| awk -F '"' '{print $4}'|awk "NR==$i"`
PhysicalSize=`nvme list --output-format=json |grep 'PhysicalSize'| awk -F ':' '{print $2/1000000000000}' |awk "NR==$i"`
printf "<name=%s sys_name=%s dn=%s sn=%s mod=%s capability=%sT>\n" $DevicePath $system_name $ModelNumber $SerialNumber $Firmware $PhysicalSize
done
}
####################################################################################
function cpu() {
model=`lscpu | grep 'Model name:' | awk '{print $3$4$5$6$7$8$9}'`
socket=`lscpu | grep 'Thread(s) per core:'| awk '{print $4}'`
core=`lscpu | grep 'Core(s) per socket:'| awk '{print $4}'`
sn=`dmidecode -t 4|grep 'Serial Number:'| awk '{print $3}'`
printf "<model=%s socket=%s core=%s sn=%s >\n" $model $socket $core $sn
}
####################################################################################
mem_info=`dmidecode -t17 | egrep -B20 'Configured Clock Speed: 1333 MT/s|Configured Clock Speed: 2400 MT/s' > ./mem_info`
type=`dmidecode -t17|grep -E 'Type:'|awk '{print $2}'|awk "NR==1"`
if [[ "$type" == DDR3 ]];then
type='DDR3'
else
type='DDR4'
fi
for ((i=1;i<=8;i++)) ; do
system_sn=`dmidecode -t1 | grep 'Serial Number:' | awk '{print $3}'`
sn=`cat ./mem_info|grep 'Serial Number:'|awk '{print $3}'| grep -vi no |awk "NR==$i"`
pn=`cat ./mem_info|grep 'Part Number:' |awk '{print $3}'| grep -vi no |awk "NR==$i"`
size=`cat ./mem_info|grep 'Size:'|awk '{print $2}' | grep -iv no|awk "NR==$i"`
l=`cat ./mem_info|grep 'Locator:'|awk '{print $2}' |grep -v 'Locator:'|awk "NR==$i"`
bl=`cat ./mem_info|grep "Bank Locator:" | awk '{print $3"_"$4"_"$5"_"$6"_"$7"_"$8}'|awk "NR==$i"`
speed_curr=`cat ./mem_info|grep 'Configured Clock Speed:'|awk '{print $4}'| grep -iv know|awk "NR==$i" `
printf "<Memory sys_sn=%s slot=%s sn=%s pn=%s size=%sMB type=%s speed_curr=%sMT/s l=%s bl=%s>\n" $system_sn None $sn $pn $size $type $speed_curr $l $bl
done
####################################################################################
nvme list --output-format=json | jq .Devices[0,1].DevicePath
nvme1=`cat nvmeinfo | jq .Devices[0].DevicePath,.Devices[0].Firmware,.Devices[0].ModelNumber,.Devices[0].SerialNumber`
nvme2=`cat nvmeinfo | jq .Devices[1].DevicePath,.Devices[1].Firmware,.Devices[1].ModelNumber,.Devices[1].SerialNumber`
printf "<nvme info: %3s %12s %8s %20s" name mod pn sn
printf "<nvme info: " ;printf "%s" $nvme1 ;printf ">"
文章来源地址https://www.toymoban.com/news/detail-664402.html
文章来源:https://www.toymoban.com/news/detail-664402.html
到了这里,关于shell收集服务器信息的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!