2014-10-06 26 views
0

这是我的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 ]

有人可以用这个错误帮助吗?

+0

记住'Seek_Error_Rate'和'Reallocated_Sector_Ct'不在估算硬盘驱动器的状况时应检查的唯一SMART参数。 – 2014-10-06 11:47:22

+1

为了回答你的问题,我们需要知道'$ status'(或者至少'$ {status [1]}'看起来像什么样子。使用'set -x'来启用调试模式,你将能够发现 – 2014-10-06 13:14:19

+0

最有可能的是,'$ {#status [@]}'是0或1,所以'$ {status [1]}'不存在。 – chepner 2014-10-06 16:32:49

回答

0

使用字符串比较,而不是数字:

if [ "${status[1]}" != "0" ] 

并检查你的状态值(你没有得到在所有情况下的数值)

+0

如果没有数据,它会报告' -',而不是可能出现问题的那个号码 – Petesh 2014-10-06 12:30:48

+0

最有可能@Petesh – klashxx 2014-10-06 14:10:48