Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用awk和计数结果分析命令输出_Bash_Parsing_Awk - Fatal编程技术网

Bash 使用awk和计数结果分析命令输出

Bash 使用awk和计数结果分析命令输出,bash,parsing,awk,Bash,Parsing,Awk,我有一个来自'multipath-ll'命令的输出 来自RHEL: mpath114 (3600507680283095ea8000000000004fa) dm-28 IBM,2145 [size=200G][features=1 queue_if_no_path][hwhandler=0][rw] \_ round-robin 0 [prio=50][active] \_ 19:0:0:40 sdea 128:32 [active][ready] \_ 20:0:1:40 sdeb 1

我有一个来自'multipath-ll'命令的输出

来自RHEL:

mpath114 (3600507680283095ea8000000000004fa) dm-28 IBM,2145
[size=200G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=50][active]
 \_ 19:0:0:40 sdea 128:32  [active][ready]
 \_ 20:0:1:40 sdeb 128:48  [active][ready]
 \_ 20:0:1:41 sdec 128:16  [failed][faulty]
\_ round-robin 0 [prio=10][enabled]
 \_ 20:0:0:40 sdba 67:64   [active][ready]
 \_ 19:0:1:40 sdgg 131:192 [active][ready]
mpath131 (3600507680283095ea800000000000504) dm-39 IBM,2145
[size=10G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=50][active]
 \_ 20:0:1:1  sdbl 67:240  [active][ready]
 \_ 19:0:0:1  sdc  8:32    [active][ready]
\_ round-robin 0 [prio=10][enabled]
 \_ 19:0:1:1  sdet 129:80  [active][ready]
 \_ 20:0:0:1  sdk  8:160   [active][ready]
[..]
或从SLES服务器:

mpathmzp (36005076801c7061ef800000000000089) dm-0 IBM,2145
size=10G features='1 queue_if_no_path' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=50 status=enabled
| `- 67:0:2:0 sde 8:64 active ready running
| `- 68:0:0:1 sdl 8:76 failed faulty running
`-+- policy='round-robin 0' prio=10 status=enabled
  |- 67:0:3:0 sdc 8:32 active ready running
  `- 68:0:0:0 sdd 8:48 active ready running
[..]
我想解析它(最好使用awk或bash),以显示配置的摘要。 它应该打印伪多路径设备和活动路径的数量以及失败的路径(如果有) 样本:

SLES也一样:

dm-0,  10G,  Total: 4 paths, active: 3, failed: 1
如果可能的话,我希望对输出进行排序,以便没有失败路径和最活跃路径的路径位于顶部,并以带有失败路径的DeviceAccess结束


谢谢你的帮助

awk
应能:

multipath -ll | awk 'NR>1 {r=f=0;for (i=1;i<=NF;i++) if ($i~/ready/) r++; else if ($i~/faulty/) f++;split($5,a,"=|]");print $3,a[2]"\tTotal: "r+f" paths, active: "r,"failed: "f}' RS="mpath" OFS=", "
dm-28, 200G     Total: 5 paths, active: 4, failed: 1
dm-39, 10G      Total: 4 paths, active: 4, failed: 0

multipath-ll | awk'NR>1{r=f=0;对于(i=1;我看你的,我的不工作,脚本…我注意到一些系统的大小不在第5个字段中。我如何动态使用它?
multipath -ll | awk 'NR>1 {r=f=0;for (i=1;i<=NF;i++) if ($i~/ready/) r++; else if ($i~/faulty/) f++;split($5,a,"=|]");print $3,a[2]"\tTotal: "r+f" paths, active: "r,"failed: "f}' RS="mpath" OFS=", "
dm-28, 200G     Total: 5 paths, active: 4, failed: 1
dm-39, 10G      Total: 4 paths, active: 4, failed: 0