shell收集服务器信息

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 "\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 "\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 "\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  "\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 " name mod pn sn
printf "  ;printf "%s" $nvme1  ;printf  ">"

你可能感兴趣的:(shell,服务器,linux,运维)