![通过 shell 脚本删除一堆断开连接的 LUN(正则表达式问题)](https://linux22.com/image/779077/%E9%80%9A%E8%BF%87%20shell%20%E8%84%9A%E6%9C%AC%E5%88%A0%E9%99%A4%E4%B8%80%E5%A0%86%E6%96%AD%E5%BC%80%E8%BF%9E%E6%8E%A5%E7%9A%84%20LUN%EF%BC%88%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E9%97%AE%E9%A2%98%EF%BC%89.png)
我的脚本有问题,不想在更改 LUN 编号的情况下运行相同的程序 200 次。从所有到 LUN 的路径中删除多路径设备,运行echo 1 > /sys/bus/scsi/devices/${H:B:T:L}/delete
(其中 H = host:B = bus:T = target:L = lun)例如,2:0:3:1 到 2:0:3:49
让我们检查一下我们的 LUN:
lsscsi
[2:0:3:33] disk NETAPP LUN C-Mode 9700 /dev/sdbt
[2:0:3:34] disk NETAPP LUN C-Mode 9700 /dev/sdbv
[2:0:3:35] disk NETAPP LUN C-Mode 9700 /dev/sdbw
[2:0:3:36] disk NETAPP LUN C-Mode 9700 /dev/sdby
[2:0:3:37] disk NETAPP LUN C-Mode 9700 /dev/sdca
[2:0:3:38] disk NETAPP LUN C-Mode 9700 /dev/sdcc
[2:0:3:39] disk NETAPP LUN C-Mode 9700 /dev/sdce
[2:0:3:40] disk NETAPP LUN C-Mode 9700 /dev/sdcg
[2:0:3:41] disk NETAPP LUN C-Mode 9700 /dev/sdci
[2:0:3:42] disk NETAPP LUN C-Mode 9700 /dev/sdck
[2:0:3:43] disk NETAPP LUN C-Mode 9700 /dev/sdcm
[2:0:3:44] disk NETAPP LUN C-Mode 9700 /dev/sdco
[2:0:3:45] disk NETAPP LUN C-Mode 9700 /dev/sdcp
清理脚本:
for IP in {1...45} ; do 'echo 1 > /sys/bus/scsi/devices/2:0:3:$IP/delete'; done
收到错误:
-bash: echo 1 > /sys/bus/scsi/devices/2:0:3:$IP/delete: No such file or directory
再试一次:
for IP in {1...45} ; do "echo 1 > /sys/bus/scsi/devices/2:0:3:$IP/delete"; done
收到错误:
-bash: echo 1 > /sys/bus/scsi/devices/2:0:3:{1...45}/delete: No such file or directory
如何隔离知识产权使其在该请求中发挥作用?
答案1
你有{1...45}
,但是语法似乎是{1..45}
。https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Brace-Expansion