【发布时间】:2014-11-30 15:49:10
【问题描述】:
这是我的 bash 脚本的一部分:
# Checking disk
for disk in $disks
do
# Creating a array with results
declare -a status=(`smartctl -a -d ata $disk | awk '/Reallocated_Sector_Ct/ || /Seek_Error_Rate/ { print $2" "$NF }'`)
# Checking that we do not have any Reallocated Sectors
if [ "${status[1]}" -ne 0 ]
then
echo "$mname Warning: Disk $disk has errors! ${status[0]} ${status[1]} ${status[2]} ${status[3]}. Following complete smartctl output." >> diskerror.log
smartctl -a -d ata $disk >> $logloc/diskerror.log
failed=("${failed[@]}" "$disk")
sendm="1"
fi
done
当我运行脚本时,bash 返回以下错误:disk_status.sh: line 38: [: : integer expression expected
错误行是:if [ "${status[1]}" -ne 0 ]
有人可以帮忙解决这个错误吗?
【问题讨论】:
-
请记住,
Seek_Error_Rate和Reallocated_Sector_Ct不是您在估计硬盘驱动器状况时应该检查的唯一 SMART 参数。 -
为了回答您的问题,我们需要知道
$status(或至少${status[1]}的样子。使用set -x启用调试模式,您将能够找出有什么造成了你的问题。 -
很可能,
${#status[@]}是 0 或 1,所以${status[1]}根本不存在。