1

The command xentop -bi1 outputs the following:

NAME  STATE   CPU(sec) CPU(%)     MEM(k) MEM(%)  MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS   VBD_OO   VBD_RD   VBD_WR  VBD_RSECT  VBD_WSECT SSID
  Domain-0 -----r      37719    0.0    2096776    6.4   no limit       n/a     1    0        0        0    0        0        0        0          0          0    0
  testvm01 --b---         69    0.0     131072    0.4     131072       0.4     1    1     2388     1670    2        0     3358    15802     154314     273808    0
xenwin2008 --b---       8208    0.0    1052628    3.2    1052672       3.2     1    2     1361        0    2        0        0        0          0          0    0

I want to output only the cpu usage of testvm01

So, i use grep: xentop -bi1 | grep testvm01

testvm01 --b---         69    0.0     131072    0.4     131072       0.4     1    1     2389     1672    2        0     3358    15826     154314     274080    0

How to get only the value "0.0"?

Vince
  • 1,133
  • 3
  • 17
  • 34

3 Answers3

3

It's easy with :

xentop -bi1 | awk '$1 == "testvm01" { print $4 }'

It yields:

0.0
Birei
  • 35,723
  • 2
  • 77
  • 82
  • How could I append a time-stamp to the output of this code: xentop -bi10 | awk '$1 == "testvm01" { print $4 }' – Ali Jul 06 '15 at 10:27
  • 1
    @Ali: Look [here](http://stackoverflow.com/questions/21564/is-there-a-unix-utility-to-prepend-timestamps-to-lines-of-text) or [here](http://stackoverflow.com/questions/14161552/add-timestamp-to-cat-output-from-shell-script) – Birei Jul 06 '15 at 10:55
2

Using :

xentop -bi1 | awk '/testvm01/{print $4}'
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
1

Or another variation of awk

xentop -bi1 | awk '$1~/testvm01/ {print $4}'
0.0
Jotne
  • 40,548
  • 12
  • 51
  • 55