【发布时间】:2021-12-29 18:40:15
【问题描述】:
实用程序“sas2ircu”可以为连接到主机的每个硬盘驱动器输出多行。单个驱动器的输出示例如下所示:
Enclosure # : 5
Slot # : 20
SAS Address : 5003048-0-185f-b21c
State : Ready (RDY)
我有一个 bash 脚本,它执行 sas2ircu 命令并对输出执行以下操作:
- 通过 RDY 字符串识别驱动器
- 将外壳的数值(即5)读入数组'enc'
- 将槽的数值(即20)读入另一个数组'槽'
我的代码达到了它的目的,但我想弄清楚是否可以将它组合成一行并运行 sas2ircu 命令一次而不是两次。
mapfile -t enc < <(/root/sas2ircu 0 display|grep -B3 RDY|awk '/Enclosure/{print $NF}')
mapfile -t slot < <(/root/sas2ircu 0 display|grep -B2 RDY|awk '/Slot/{print $NF}')
我已经阅读了大量关于 awk 的内容,但我对它还是很陌生,还没有想出比我所拥有的更好的东西。有什么建议吗?
【问题讨论】: