Ubuntu Server 22.04 中监控硬盘温度的工具

Ubuntu Server 22.04 中监控硬盘温度的工具

Ubuntu Server 22.04 中是否有监控硬盘温度的工具?我知道有hddtemp、、和等工具smartmontools,但没有一个能显示我的硬盘温度。lsm-sensorsinxi

硬盘温度

安装它时sudo apt-get install hddtemp显示它在我的 Ubuntu 版本中不可用。

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package hddtemp is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'hddtemp' has no installation candidate

smartmontools、lsm-sensors 和 inxi

此包在我的版本中可用,但不输出我的硬盘温度。我假设需要配置某些传感器才能获取硬盘温度。

我所做的是:

  1. 安装inxisudo apt-get install inxi
  2. 配置lsm-sensorssudo sensors-detect
  3. 跑步sudo inxi -xD

输出:

Local Storage: total: 11.83 TiB used: 17.17 GiB (0.1%)
ID-1: /dev/sda vendor: Seagate model: ST1000LM035-1RK172 size: 931.51 GiB
ID-2: /dev/sdb vendor: Western Digital model: WD6NPURX-64JC5Y0 size: 5.46 TiB
ID-3: /dev/sdc vendor: Western Digital model: WD6NPURX-64JC5Y0 size: 5.46 TiB

smartmontools甚至如图所示运行这里不提供硬盘温度。

我也在这里研究过,但无济于事。

例子

  1. Ubuntu 22.04 中的 CPU 和 HDD 温度
  2. 如何检查USB HDD温度?
  3. 如何检查USB HDD温度?

答案1

用于 GUI

sudo apt install gsmartcontrol

或者在终端

sudo smartctl -A /dev/sd(your drive letter) | grep -i temperature

这将显示或打印 SDD/HDD 的正确温度

答案2

要读取 Ubuntu 22.04 中的 HDD 温度,您需要使用,在加载模块时hwmon可以使用来访问。sensorsdrivetemp

sudo apt install lm-sensors
sudo modprobe drivetemp
sensors

为了drivetemp每次启动时自动加载,请将其添加到 /etc/modules 中,如下所示:

echo drivetemp | sudo tee -a /etc/modules

答案3

除了我之前的回答之外,我发现最可靠的温度数据来源仍然是 smartctl。这允许按/dev名称进行匹配,但它更加混乱,需要如下脚本:

#!/bin/bash
DRIVEPATH="$1"
INFO="$(sudo smartctl -a $DRIVEPATH)"
TEMP=$(echo "$INFO" | grep '194 Temp' | awk '{print $10}')
if [[ $TEMP == '' ]]; then
  TEMP=$(echo "$INFO" | grep '190 Airflow' | awk '{print $10}')
fi
if [[ $TEMP == '' ]]; then
  TEMP=$(echo "$INFO" | grep 'Temperature Sensor 1:' | awk '{print $4}')
fi
if [[ $TEMP == '' ]]; then
  TEMP=$(echo "$INFO" | grep 'Current Drive Temperature:' | awk '{print $4}')
fi
if [[ $TEMP == '' ]]; then
  TEMP=$(echo "$INFO" | grep 'Temperature:' | awk '{print $2}')
fi
echo $TEMP

例子:

$ sudo gethddtemp /dev/sda
34

也许可以将其改进for为每个语句一个循环grep | awk

以上适用于我们所有的 SATA HDD、SATA SSD、SAS HDD 和 NVMe 驱动器,但可能需要更多案例来支持其他供应商、型号和接口。

答案4

这里是:

#!/bin/bash

# Function to check if a drive exists and retrieve its temperature
get_drive_temperature() {
  local drive="$1"
  local info="$(sudo smartctl -a $drive)"
  local temp=$(echo "$info" | grep '194 Temp' | awk '{print $10}')
  if [[ $temp == '' ]]; then
    temp=$(echo "$info" | grep '190 Airflow' | awk '{print $10}')
  fi
  if [[ $temp == '' ]]; then
    temp=$(echo "$info" | grep 'Temperature Sensor 1:' | awk '{print $4}')
  fi
  if [[ $temp == '' ]]; then
    temp=$(echo "$info" | grep 'Current Drive Temperature:' | awk '{print $4}')
  fi
  if [[ $temp == '' ]]; then
    temp=$(echo "$info" | grep 'Temperature:' | awk '{print $2}')
  fi
  echo "$temp"
}

# Function to retrieve the core temperature
get_core_temperature() {
  local core_temp=$(sensors | grep 'Core 0:' | awk '{print $3}')
  echo "$core_temp"
}

# Get and print core temperature first
core_temperature=$(get_core_temperature)
echo "Core temperature: $core_temperature"

# Print drive temperatures
for drive in /dev/sd?; do
  if [ -e "$drive" ]; then
    temperature=$(get_drive_temperature "$drive")
    echo "$drive temperature: $temperature DegC"
  fi
done

相关内容