我需要扫描iostat -En
Solaris 机器上的输出,以便在找到有错误的磁盘时,将有关该磁盘的两行发送到最终输出。到目前为止,这工作正常
iostat -En | grep 'Errors: [1-9]' -A 1
但是当我尝试不包括 CD/DVD 设备时,我碰壁了。contaxt 标志 ( -A|B|C
) 似乎不起作用,-v
所以我不能使用它:
-bash-4.0$ iostat -En | grep -B 1 -vi "CD/DVD" | grep 'Errors: [1-9]' -A 1
c0t3d0 Soft Errors: 2 Hard Errors: 0 Transport Errors: 0
Vendor: TSSTcorp Product: CD/DVDW TS-L632D Revision: SR02 Serial No:
我认为这里不应该有任何输出,因为包含“CD/DVD”的行和它之前的行应该被删除。将其编写为任何语言的脚本都很简单,但它必须是一个可以在没有安装额外脚本的主机上运行的命令,所以我想perl -e
可以使用。我不知道任何perl,所以我没有尝试过这种方法。
一些示例iostat -En
输出:
-bash-4.0$ iostat -En
c0t0d0 Soft Errors: 0 Hard Errors: 0 Transport Errors: 0
Vendor: SEAGATE Product: ST973402SSUN72G Revision: 0603 Serial No: *removed*
Size: 73.40GB <73400057856 bytes>
Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
Illegal Request: 0 Predictive Failure Analysis: 0
c0t3d0 Soft Errors: 2 Hard Errors: 0 Transport Errors: 0
Vendor: TSSTcorp Product: CD/DVDW TS-L632D Revision: SR02 Serial No:
Size: 0.00GB <0 bytes>
Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
Illegal Request: 2 Predictive Failure Analysis: 0
c0t1d0 Soft Errors: 0 Hard Errors: 0 Transport Errors: 0
Vendor: SEAGATE Product: ST973402SSUN72G Revision: 0603 Serial No: *removed*
Size: 73.40GB <73400057856 bytes>
Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
Illegal Request: 0 Predictive Failure Analysis: 0
在这种情况下,我不应该有任何输出,因为唯一有错误的设备是光驱,我不关心这些。
c0t1d0 Soft Errors: 0 Hard Errors: 1 Transport Errors: 0
Vendor: SEAGATE Product: ST973402SSUN72G Revision: 0603 Serial No: *removed*
这是我正在寻找的输出。有任何想法吗?