op-packages/luci-app-smartinfo/root/usr/lib/smartinfo/smart_functions.sh
github-actions[bot] 32600acc60 🌴 Sync 2026-03-05 23:51:42
2026-03-05 23:51:42 +08:00

57 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Copyright (C) 2016 NVACG , 穿越蓝天/animefans_xj
# af_xj@hotmail.com
#
#Licensed under the GNU GPL License, Version 3 (the "license");
#you may not use this file except in compliance with the License.
#you may obtain a copy of the License at
#
# http://www.gnu.org/licenses/gpl.txt
do_smart_check() {
# 看看指定的设备是否在线
if [ -b $1 ]; then
# 如果在线看看是否支持S.M.A.R.T。支持则对其执行SMART检测判断输出是否包含PASSED
result=`/usr/sbin/smartctl -d sat -H $1`
if [ $? -eq "2" ]; then
# 不支持S.M.A.R.T
return 3
fi
result=`echo $result | grep -c PASSED`
if [ $result -ne 0 ]; then
#无故障
return 0
else
#故障
return 1
fi
else
# 设备离线
return "2"
fi
}
do_simple_smart_check() {
# 看看指定的设备是否在线
if [ -b $1 ]; then
# 如果在线则对其执行SMART检测判断输出是否包含PASSED
result=`/usr/sbin/smartctl -d sat -H $1`
if [ $? -eq "2" ]; then
# 不支持S.M.A.R.T
echo "$1:Unsupported"
exit 0
fi
result=`echo $result | grep -c PASSED`
if [ $result -ne 0 ]; then
echo "$1:OK"
else
echo "$1:Failed"
fi
else
# 如果不在线则输出设备离线
echo "$1:Offline"
fi
}