[wplug] Looking for scripting help to parse information

Patrick Wagstrom patrick at wagstrom.net
Fri Mar 14 08:46:42 EST 2008


Rob Lines wrote:
> Good morning.
> 
> I am trying to get some information from the ipmitool specifically the 
> temperature readings for the CPUs and the ambient temperature.  I can 
> run the command and it gives me the 3 values on separate lines.  For 
> other sensors I can just use grep to find the distinct name of the 
> sensors but with temperature they are all similar.  The CPU values are 
> named Temp and the ambient temperature is called Ambient Temp.  So while 
> I can run the output through grep to find the ambient temperature there 
> isn't anything distinct for the two CPU values.  But they always show up 
> in the same order so what I would like to do is have a way to grab a 
> specific line and save that into a variable.  I am sure there is a 
> simple way to do this I am just not sure where to look for it.
> 
> I would prefer to avoid using perl and just stick to shell scripting if 
> possible.

I'm not completely clear on the situation, but it sounds like head and tail 
could be useful here.

For example, if you know that the output of grep will produce only two 
lines, and you just need the last one do this:

YOURTOOL | grep YOURSTRING | tail -n 1

However, if your tool produces a variable amount of lines and you need just 
line 2, you can do this:

YOURTOOL | grep YOURSTRING | head -n 2 | tail -n 1

There's probably some fancy multiline regex you could use with egrep, but I 
find this to be pretty readable for me.

--Patrick



More information about the wplug mailing list