You are not logged in.

#1 2011-06-20 21:00:37

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,673
Website

parsing simple output help needed

Goal: for each hostname (mars, phobos, and deimos grab the value of state = in a variable so I work on it further.

I figured I'll need to use sed to find the target host name, then substitute the "linefeed and what I am assuming is a tab state =" to null and grab the state (in this case "free") into a variable.  What I don't know how to do is: see the output of the command showing all non-printable characters so I can setup a grep or sed line.  How is this accomplished in bash?

$ pbsnodes
mars
     state = free
     np = 4
     ntype = cluster
     status = rectime=1308479899,varattr=,jobs=0.localhost.localdomain,state=free,netload=1638547057,
gres=,loadave=2.69,ncpus=4,physmem=8195892kb,availmem=7172508kb,totmem=8195892kb,
idletime=24772,nusers=1,nsessions=5,sessions=1333 1349 1353 1388 9095,
uname=Linux mars 2.6.39-ck #1 SMP PREEMPT Sat Jun 18 14:19:01 EDT 2011 x86_64,opsys=linux
     mom_service_port = 15002
     mom_manager_port = 15003
     gpus = 2

phobos
     state = free
     np = 2
     ntype = cluster
     status = rectime=1308479933,varattr=,jobs=,state=free,netload=1085755815,
gres=,loadave=2.84,ncpus=2,physmem=4019704kb,availmem=5753552kb,totmem=6116852kb,
idletime=7324,nusers=2,nsessions=6,sessions=1565 1562 1691 1716 1737 1851,
uname=Linux phobos 2.6.37-ck #1 SMP PREEMPT Sun Apr 3 17:16:35 EDT 2011 x86_64,opsys=linux
     mom_service_port = 15002
     mom_manager_port = 15003
     gpus = 1

deimos
     state = free
     np = 2
     ntype = cluster
     status = rectime=1308479890,varattr=,jobs=2.localhost.localdomain,state=free,netload=527239670,
gres=,loadave=0.52,ncpus=2,physmem=4057808kb,availmem=3955624kb,totmem=4057808kb,
idletime=644,nusers=1,nsessions=1,sessions=865,
uname=Linux deimos 2.6.39-ck #1 SMP PREEMPT Sat Jun 11 12:36:21 EDT 2011 x86_64,opsys=linux
     mom_service_port = 15002
     mom_manager_port = 15003
     gpus = 1

Last edited by graysky (2011-06-20 21:00:53)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2011-06-20 22:28:33

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: parsing simple output help needed

I'm not sure if I understand you correctly nor am i very good with regexp but this should put the hostnames in one array and the states in another.

hostarray=( $(grep -B1 'state '  filename | grep '^[A-Za-z0-9]') )
statearray=( $(grep -B1 'state '  filename | grep '[[:space:]]' | awk '{print $3}') )

no place like /home
github

Offline

#3 2011-06-20 23:06:09

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: parsing simple output help needed

You could use something like this:

pbsnodes | awk 'NF == 1 { host = $1 } $1 == "state" { print host, $3 }'

Stuff it in an array and you get host/state pairs.

Offline

#4 2011-06-22 22:46:50

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: parsing simple output help needed

graysky wrote:

What I don't know how to do is: see the output of the command showing all non-printable characters so I can setup a grep or sed line.  How is this accomplished in bash?

$ pbsnodes | od -c

Offline

#5 2011-07-01 02:54:39

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: parsing simple output help needed

quigybo wrote:
graysky wrote:

What I don't know how to do is: see the output of the command showing all non-printable characters so I can setup a grep or sed line.  How is this accomplished in bash?

$ pbsnodes | od -c

Or 'cat -A'.

Offline

Board footer

Powered by FluxBB