我有一个DISK_INFO
使用以下内容调用的变量:
diskid HGST HUSMH8010BSS204 serial no no [0] Slot00
diskid HGST HUH728080AL4204 serial no no [0] Slot02
diskid HGST HUH728080AL4204 serial no no [0] Slot03
diskid HGST HUH728080AL4204 serial no no [0] Slot04
diskid HGST HUH728080AL4204 serial no no [0] Slot05
diskid HGST HUH728080AL4204 serial no no [0] Slot06
diskid HGST HUH728080AL4204 serial no no [0] Slot07
diskid HGST HUH728080AL4204 serial no no [0] Slot08
diskid HGST HUH728080AL4204 serial no no [0] Slot09
diskid HGST HUH728080AL4204 serial no no [0] Slot10
diskid HGST HUH728080AL4204 serial no no [0] Slot11
diskid HGST HUH728080AL4204 serial no no [0] Slot12
diskid HGST HUH728080AL4204 serial no no [0] Slot13
diskid HGST HUH728080AL4204 serial no no [0] Slot14
diskid HGST HUH728080AL4204 serial no no [0] Slot15
diskid HGST HUH728080AL4204 serial no no [0] Slot16
diskid HGST HUH728080AL4204 serial no no [0] Slot17
diskid HGST HUH728080AL4204 serial no no [0] Slot18
diskid HGST HUH728080AL4204 serial no no [0] Slot19
diskid HGST HUH728080AL4204 serial no no [0] Slot20
diskid HGST HUH728080AL4204 serial no no [0] Slot21
diskid HGST HUH728080AL4204 serial no no [0] Slot22
diskid HGST HUH728080AL4204 serial no no [0] Slot23
diskid HGST HUH728080AL4204 serial no no [1] Slot00
diskid HGST HUH728080AL4204 serial no no [1] Slot01
diskid HGST HUH728080AL4204 serial no no [1] Slot02
diskid HGST HUH728080AL4204 serial no no [1] Slot03
diskid HGST HUH728080AL4204 serial no no [1] Slot04
diskid HGST HUH728080AL4204 serial no no [1] Slot05
diskid HGST HUH728080AL4204 serial no no [1] Slot06
diskid HGST HUH728080AL4204 serial no no [1] Slot07
diskid HGST HUH728080AL4204 serial no no [1] Slot08
diskid HGST HUH728080AL4204 serial no no [1] Slot09
diskid HGST HUH728080AL4204 serial no no [1] Slot10
diskid HGST HUH728080AL4204 serial no no [1] Slot11
c2t0d0 Kingston DataTraveler 2.0 - - - -
当磁盘发生故障时,它将从此列表中删除,在此示例中,机箱 0 插槽 01 中的磁盘发生故障。
假设机柜 0 总是有 24 个磁盘 00-23,机柜 1 总是有 12 个磁盘 00-11,我怎样才能有效和准确地确定丢失的磁盘?
我目前有以下内容,但我确信这可以在单个 awk 命令中完成:
enclosure0=($(awk '$7 ~ "[0]"{print $8}' <<<"$DISK_INFO" | sort -n))
enclosure1=($(awk '$7 ~ "[1]"{print $8}' <<<"$DISK_INFO" | sort -n))
for n in {00..23}; do
grep -q "$n" <<<"${enclosure0[@]}" || missing+=("Enclosure 0 - Slot$n")
done
for n in {00..11}; do
grep -q "$n" <<< "${enclosure1[@]}" || missing+=("Enclosure 1 - Slot$n")
done
没有
awk
, 对于每个外壳:慢动作:
printf '[0] Slot%s\n' {00..23}
生成所有可能磁盘的列表grep -Eo '\[0\] Slot..' disks
提取现有磁盘sort | uniq -u
提取只出现一次的行您可以用适当的函数替换 printf 和 grep 步骤,或者用另一个文件上的类似 grep 替换 printf 部分,该文件是预期的磁盘列表。
由于您事先知道哪些项目需要存在,因此请创建一个列表并在您看到它们时勾选它们。
解释: