[quote][size=2][url=forum.php?mod=redirect&goto=findpost&pid=156542&ptid=33403][color=#999999]飞牛技术同学 发表于 2025-8-7 18:34[/color][/url][/size]
是内置还是外接的硬盘?[/quote]
我的硬盘是 奥睿科 9558RU3阵列柜(JMS567+JMS575),也不能在飞牛里面看smart。飞牛系统有钩子或者接口把自己查到的smart同步到飞牛的存储管理里面么?
#!/bin/bash
# 智能USB硬盘健康检查脚本
# 自动检测可用设备并检查健康状态
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}智能USB硬盘健康检查工具${NC}"
echo "================================"
# 自动检测可用设备
echo "正在检测可用设备..."
available_devices=()
for device in /dev/sd[a-z]; do
if [ -b "$device" ]; then
echo -n "检测 $device: "
# 尝试获取设备信息,即使返回码不为0
smart_output=$(sudo smartctl -i "$device" -d sat 2>&1)
if echo "$smart_output" | grep -q "Device Model:"; then
model=$(echo "$smart_output" | grep "Device Model:" | cut -d: -f2 | xargs)
if [ -n "$model" ]; then
echo -e "${GREEN}可用${NC} (型号: $model)"
available_devices+=("$device")
else
echo -e "${YELLOW}无法获取型号${NC}"
fi
else
echo -e "${RED}无法访问${NC}"
fi
fi
done
echo ""
if [ ${#available_devices[@]} -eq 0 ]; then
echo -e "${RED}未找到可用的硬盘设备${NC}"
echo ""
echo "可能的原因:"
echo "1. USB硬盘未连接"
echo "2. 设备名称不是 /dev/sd*"
echo "3. 需要不同的smartctl参数"
echo "4. 权限问题"
echo ""
echo "请运行以下命令进行详细诊断:"
echo "sudo ./device_check.sh"
exit 1
fi
echo -e "${GREEN}找到 ${#available_devices[@]} 个可用设备${NC}"
echo ""
# 检查每个可用设备
for device in "${available_devices[@]}"; do
echo -e "\n${BLUE}检查设备: $device${NC}"
echo "----------------------------------------"
# 获取SMART状态
echo "获取SMART数据..."
smart_output=$(sudo smartctl -a "$device" -d sat 2>&1)
if [ -z "$smart_output" ] || ! echo "$smart_output" | grep -q "Device Model:"; then
echo -e "${RED}无法获取 $device 的SMART数据${NC}"
continue
fi
# 提取基本信息
model=$(echo "$smart_output" | grep "Device Model:" | cut -d: -f2 | xargs)
serial=$(echo "$smart_output" | grep "Serial Number:" | cut -d: -f2 | xargs)
smart_status=$(echo "$smart_output" | grep "SMART overall-health self-assessment test result:" | cut -d: -f2 | xargs)
echo "型号: $model"
echo "序列号: $serial"
echo -n "SMART状态: "
if [ "$smart_status" = "PASSED" ]; then
echo -e "${GREEN}PASSED${NC}"
else
echo -e "${RED}FAILED${NC}"
fi
# 提取关键指标
echo "关键指标:"
# 重分配扇区
realloc=$(echo "$smart_output" | grep "Reallocated_Sector_Ct" | awk '{print $10}')
if [ "$realloc" = "0" ] || [ -z "$realloc" ]; then
echo -e " 重分配扇区: ${GREEN}0${NC}"
else
echo -e " 重分配扇区: ${RED}$realloc${NC}"
fi
# 待处理扇区
pending=$(echo "$smart_output" | grep "Current_Pending_Sector" | awk '{print $10}')
if [ "$pending" = "0" ] || [ -z "$pending" ]; then
echo -e " 待处理扇区: ${GREEN}0${NC}"
else
echo -e " 待处理扇区: ${RED}$pending${NC}"
fi
# 不可纠正扇区
uncorrectable=$(echo "$smart_output" | grep "Offline_Uncorrectable" | awk '{print $10}')
if [ "$uncorrectable" = "0" ] || [ -z "$uncorrectable" ]; then
echo -e " 不可纠正扇区: ${GREEN}0${NC}"
else
echo -e " 不可纠正扇区: ${RED}$uncorrectable${NC}"
fi
# 温度
temp_line=$(echo "$smart_output" | grep "Temperature_Celsius")
if [ -n "$temp_line" ]; then
temp_raw=$(echo "$temp_line" | awk '{print $10}' | sed 's/(.*//')
if [[ "$temp_raw" =~ ^[0-9]+$ ]] && [ "$temp_raw" -ge 0 ] 2>/dev/null; then
if [ "$temp_raw" -le 45 ]; then
echo -e " 温度: ${GREEN}${temp_raw}°C${NC}"
elif [ "$temp_raw" -le 50 ]; then
echo -e " 温度: ${YELLOW}${temp_raw}°C${NC}"
else
echo -e " 温度: ${RED}${temp_raw}°C${NC}"
fi
else
echo -e " 温度: ${YELLOW}无法解析${NC}"
fi
else
echo -e " 温度: ${YELLOW}未找到${NC}"
fi
# 使用时间
power_line=$(echo "$smart_output" | grep "Power_On_Hours")
if [ -n "$power_line" ]; then
power_hours_raw=$(echo "$power_line" | awk '{print $10}')
if [[ "$power_hours_raw" =~ ^[0-9]+$ ]] && [ "$power_hours_raw" -gt 0 ] 2>/dev/null; then
years=$((power_hours_raw / 8760))
if [ "$years" -le 3 ]; then
echo -e " 使用时间: ${GREEN}${years}年${NC}"
elif [ "$years" -le 5 ]; then
echo -e " 使用时间: ${YELLOW}${years}年${NC}"
else
echo -e " 使用时间: ${RED}${years}年${NC}"
fi
else
echo -e " 使用时间: ${YELLOW}无法获取${NC}"
fi
else
echo -e " 使用时间: ${YELLOW}未找到${NC}"
fi
# UDMA CRC错误
crc_line=$(echo "$smart_output" | grep "UDMA_CRC_Error_Count")
if [ -n "$crc_line" ]; then
crc_errors_raw=$(echo "$crc_line" | awk '{print $10}')
if [[ "$crc_errors_raw" =~ ^[0-9]+$ ]] && [ "$crc_errors_raw" -ge 0 ] 2>/dev/null; then
if [ "$crc_errors_raw" -le 10 ]; then
echo -e " UDMA CRC错误: ${GREEN}$crc_errors_raw${NC}"
else
echo -e " UDMA CRC错误: ${YELLOW}$crc_errors_raw${NC}"
fi
else
echo -e " UDMA CRC错误: ${YELLOW}无法获取${NC}"
fi
else
echo -e " UDMA CRC错误: ${YELLOW}未找到${NC}"
fi
# 健康评估
echo -n "健康评估: "
if [ "$smart_status" = "PASSED" ] && [ "$realloc" = "0" ] && [ "$pending" = "0" ] && [ "$uncorrectable" = "0" ]; then
echo -e "${GREEN}健康${NC}"
elif [ "$smart_status" = "PASSED" ]; then
echo -e "${YELLOW}需要注意${NC}"
else
echo -e "${RED}有问题${NC}"
fi
echo "----------------------------------------"
done
echo -e "\n${BLUE}检查完成${NC}"
echo "提示:"
echo " - 绿色: 正常"
echo " - **: 需要注意"
echo " - 红色: 有问题"
echo ""
echo "建议定期运行此脚本监控硬盘健康状况"