0

I would like to have some help writing a script (which should works on freebsd where I have sh as default) that should grab a precise character when I do a "ps ax | grep" command from the terminal. For example :

# ps ax | grep bhyve

12098  -  Is      0:00.00 bhyve: system.pwd (bhyve)
12099  -  Is      0:00.00 bhyve: system.grp (bhyve)
12093  1  IC+    25:11.49 bhyve: vm4 (bhyve)
12557  0  S+      0:00.00 grep bhyve

it should returns 4. The command below returns the wrong values :

# ps ax | awk '/bhyve: vm/{print $6}'
vm4
/bhyve:

for sure I don't need that it returns /bhyve: !

AND :

# ps ax | grep vnc

12105  1  S+      0:00.04 vncviewer 0:4
12642  0  S+      0:00.00 grep vnc

it should be 4,but the command below returns also the wrong values :

# ps ax | awk '/vncviewer 0/{print $6}'
0:4
/vncviewer

even here,it returns /vncviewer. I don't want that.

the solution proposed worked in this way :

# ps ax | awk '/vncviewer [0]/{print $6}'
0:4

# ps ax | awk '/bhyve: [0]/{print $6}'
0:4
3

0

Browse other questions tagged .