这是我的bash脚本的一部分: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:第38行:::整数预计表达
错误行是:if [ "${status[1]}" -ne 0 ]
有人可以用这个错误帮助吗?
记住'Seek_Error_Rate'和'Reallocated_Sector_Ct'不在估算硬盘驱动器的状况时应检查的唯一SMART参数。 – 2014-10-06 11:47:22
为了回答你的问题,我们需要知道'$ status'(或者至少'$ {status [1]}'看起来像什么样子。使用'set -x'来启用调试模式,你将能够发现 – 2014-10-06 13:14:19
最有可能的是,'$ {#status [@]}'是0或1,所以'$ {status [1]}'不存在。 – chepner 2014-10-06 16:32:49