From d2d5f410ebb6d72239718b70edca3002b97120c3 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 5 May 2023 18:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A3=81=E7=9B=98=E5=81=A5?= =?UTF-8?q?=E5=BA=B7=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check_disk_health.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 check_disk_health.sh diff --git a/check_disk_health.sh b/check_disk_health.sh new file mode 100644 index 0000000..c2b9258 --- /dev/null +++ b/check_disk_health.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# 检查 smartmontools 是否已安装 +if [ -x "$(command -v smartctl)" ]; then + echo "smartmontools 已安装" +else + echo "正在安装 smartmontools..." + if [ -x "$(command -v apt-get)" ]; then + sudo apt-get update && sudo apt-get install -y smartmontools + elif [ -x "$(command -v yum)" ]; then + sudo yum install -y smartmontools + else + echo "无法确定包管理器,请手动安装 smartmontools" + exit 1 + fi +fi + +# 获取磁盘设备列表 +disks=$(lsblk -dpno NAME,TYPE | awk '$2=="disk" {print $1}') + +# 检查磁盘健康状况 +for disk in $disks; do + echo "正在检查磁盘 $disk 的健康状况..." + health_status=$(sudo smartctl -H $disk | grep "SMART overall-health") + echo "磁盘 $disk 的健康状况:$health_status" + echo "----------------------------------------" +done