简体   繁体   English

如何使用grep / regex / cut / awk / sed等提取drbd状态

[英]How to extract drbd status using grep/regex/cut/awk/sed etc

From my output from /proc/drbd I am trying to extract 'UpToDate/UpToDate' section of this output per device (0 and 1). 从/ proc / drbd的输出中,我尝试从每个设备(0和1)中提取此输出的“ UpToDate / UpToDate”部分。 I tried: 我试过了:

cat /proc/drbd  | grep ' 0:' | grep -Eo 'ds:(.*)'

But that gives me: 但这给了我:

ds:UpToDate/UpToDate C r-----

That is not what I'm looking for (looking for getting the slot where UpToDate/UpToDate propagates) or basically a return of 'UpToDate/UpToDate'..Anyways, here is the output of /proc/drbd: 那不是我想要的(寻找要获取UpToDate / UpToDate传播的插槽)或基本上不是'UpToDate / UpToDate'的返回值。无论如何,这是/ proc / drbd的输出:

  0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
  1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----

You can use the following grep command: 您可以使用以下grep命令:

grep -o 'ds[^[:space:]]\+' /proc/drbd

If you don't want the ds: in front, you can use grep in perl mode (if you have GNU grep ): 如果您不希望使用ds:可以在perl模式下使用grep(如果您有GNU grep ):

grep -oP 'ds:\K[^\s]+' /proc/drbd

the \\K clears everything which has been matched before - in this case ds: . \\K清除之前已匹配的所有内容-在这种情况下为ds:

If you don't have GNU grep , you can use awk : 如果您没有GNU grep ,则可以使用awk

awk -F'[: ]' '{print $8}' /proc/drbd

or sed : sed

sed 's/.*ds:\([^[:space:]]\+\).*/\1/' /proc/drbd

You can use the following commands to query the status of DRBD devices: 您可以使用以下命令查询DRBD设备的状态:

# drbdadm role <resource>
# drbdadm cstate <resource>
# drbdadm dstate <resource>

使用以下正则表达式:

grep -o 'ds:([^ ]*)'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM