1

From my output from /proc/drbd I am trying to extract 'UpToDate/UpToDate' section of this output per device (0 and 1). 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:

  0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
  1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
sgwrist
  • 25
  • 2

3 Answers3

2

You can use the following commands to query the status of DRBD devices:

# drbdadm role <resource>
# drbdadm cstate <resource>
# drbdadm dstate <resource>
Matt Kereczman
  • 477
  • 4
  • 9
1

You can use the following grep command:

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):

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

the \K clears everything which has been matched before - in this case ds:.

If you don't have GNU grep, you can use awk:

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

or sed:

sed 's/.*ds:\([^[:space:]]\+\).*/\1/' /proc/drbd
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
0

Use the below regex:

grep -o 'ds:([^ ]*)'
Rahul
  • 3,479
  • 3
  • 16
  • 28