【问题标题】:BASH Disk Status: integer expression expectedBASH 磁盘状态:需要整数表达式
【发布时间】: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_RateReallocated_Sector_Ct 不是您在估计硬盘驱动器状况时应该检查的唯一 SMART 参数。
  • 为了回答您的问题,我们需要知道$status(或至少${status[1]} 的样子。使用set -x 启用调试模式,您将能够找出有什么造成了你的问题。
  • 很可能,${#status[@]} 是 0 或 1,所以 ${status[1]} 根本不存在。

标签: linux bash disk disk-io


【解决方案1】:

使用字符串比较代替数字:

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

然后检查你的状态值(在所有情况下你都没有得到一个数值)

【讨论】:

  • 如果没有数据,它会报告-,而不是可能出现问题的数字
猜你喜欢
  • 2017-07-12
  • 2013-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-02
相关资源
最近更新 更多