命令行使用for循环依次执行多条命令

使用场景:

更新SAS HBA 固件,但是系统有多个sg device:

./SeaChest --scan |grep SEAG
SEAGATE  /dev/sg10    ST10000NM0096           ZA273EM0               E002
SEAGATE  /dev/sg11    ST10000NM0096           ZA26YMJF               E002
SEAGATE  /dev/sg12    ST10000NM0096           ZA273GF5               E002
SEAGATE  /dev/sg13    ST10000NM0096           ZA26XK5S               E002
SEAGATE  /dev/sg2     ST10000NM0096           ZA26YGQF               E002
SEAGATE  /dev/sg3     ST10000NM0096           ZA26Y6Z0               E002
SEAGATE  /dev/sg4     ST10000NM0096           ZA26Y561               E002
SEAGATE  /dev/sg5     ST10000NM0096           ZA26YDCQ               E002
SEAGATE  /dev/sg6     ST10000NM0096           ZA273FAS               E002
SEAGATE  /dev/sg7     ST10000NM0096           ZA273H1D               E002
SEAGATE  /dev/sg8     ST10000NM0096           ZA26Y5HX               E002
SEAGATE  /dev/sg9     ST10000NM0096           ZA26Y55V               E002

需要依次执行./SeaChest -d /dev/ --downloadFW …/…/firmware/TatsuEntCapSAS-STD-5xxE-E005.LOD命令。

这里的变量为sg设备编号,可以用下面这个命令依次遍历。

需要注意的是, 输入完for i in 3 4 5 6 7 8 9; do后直接回车就好了, 然后输入要循环执行的语句。

for i in 3 4 5 6 7 8 9; do
> ./SeaChest -d /dev/sg${i}  --downloadFW ../../firmware/TatsuEntCapSAS-STD-5xxE-E005.LOD
> done
==========================================================================================
 SeaChest_Firmware - Seagate drive utilities
 Copyright (c) 2014-2018 Seagate Technology LLC and/or its Affiliates, All Rights Reserved
 SeaChest_Firmware Version: 2.5.2-1_18_0 X86_64
 Build Date: May  7 2018
 Today: Wed Jun 19 19:11:11 2019
==========================================================================================

/dev/sg3 - ST10000NM0096 - ZA26Y6Z00000C840JPKN - SCSI
....
Firmware Download successful
Firmware Download time (s): 4.98
Average time/segment  (ms): 83.03
Activate Time          (s): 4.69
New firmware version is E005

==========================================================================================
 SeaChest_Firmware - Seagate drive utilities
 Copyright (c) 2014-2018 Seagate Technology LLC and/or its Affiliates, All Rights Reserved
 SeaChest_Firmware Version: 2.5.2-1_18_0 X86_64
 Build Date: May  7 2018
 Today: Wed Jun 19 19:11:20 2019
==========================================================================================

/dev/sg4 - ST10000NM0096 - ZA26Y5610000C840CGGZ - SCSI
....
Firmware Download successful
Firmware Download time (s): 4.99
Average time/segment  (ms): 83.19
Activate Time          (s): 4.70
New firmware version is E005

你可能感兴趣的:(命令行使用for循环依次执行多条命令)