
@byxiaoxie3 周前
03/15
21:46
1. 安装温度查询工具
apt install lm-sensors nvme-cli smartmontools -y
2. Shell脚本
#!/bin/bash
echo "=== 硬盘温度 ==="
# NVMe 硬盘
for disk in $(ls /dev/nvme[0-9]n1 2>/dev/null); do
model=$(lsblk -no MODEL $disk | tr -d '\n')
temp=$(nvme smart-log $disk | grep "temperature" | awk '{print $3}' | sed 's/[^0-9]//g')
if [ -n "$model" ] && [ -n "$temp" ]; then
echo -e "类别:NVMe 型号:$model 温度:$temp°C"
fi
done
# SATA 硬盘
for disk in $(ls /dev/sd[a-z] 2>/dev/null); do
model=$(lsblk -no MODEL $disk | tr -d '\n')
temp=$(smartctl -A $disk | grep "Temperature_Celsius" | awk '{print $10}' | sed 's/[^0-9]//g')
if [ -n "$model" ] && [ -n "$temp" ]; then
echo -e "类别:SATA 型号:$model 温度:$temp°C"
fi
done
效果图: