Re: grep help? - Trying to extra sensors data

From: The Hobbit (Bilbo.Baggins_at_bag.end.invalid)
Date: 09/15/04


Date: Wed, 15 Sep 2004 22:22:05 +1200


"Genius" <genius@onthenet.org> wrote in message
news:6639758.UWrncvuQV6@genius...
> The Hobbit wrote:
>
> > Hi All,
> > I'm trying to extract some data from my sensors output which looks like
> > the following:
> > --------------------------------------------------
> > $ sensors
> >
> > asb100-i2c-0-2d
> > Adapter: SMBus Via Pro adapter at e800
<Snippage>
> > M/B Temp: +29°C (high = +45°C, hyst = +40°C)
> > CPU Temp (Intel):
> > +46°C (high = +60°C, hyst = +50°C)
> > Power Temp:
> > +14°C (high = +45°C, hyst = +40°C)
> > CPU Temp (AMD):
> > +51°C (high = +60°C, hyst = +50°C)
> > vid: +1.850 V
> > alarms:
> >
> > $
> > --------------------------------------------------
<Snippage>
>
> try preprocessing like this:
>
> sensors | sed '/:$/{N;s/\n//;}' | awk -F: '$1=="Chassis Fan"{print
$2}'
>
> when sed sees line ending in : it just reads next line, then substitutes
the
> embedded newline for nothing. the braces group commands together.
> you might find awk more useful than cut for some things because
> awk has handy substr function too.
>
Awesome - thanks for that genius, I'm much of the way there, now I'm just
trying to get around some weirdness with the special characters which
accompany the degrees symbol.

My current temperature extraction command is as follows (probably HORRIBLY
inefficient, but I've got to go join the wife i nfront of the telly so
haven't had too much time to figure out what to do to tidy it).
Aaaanyway...:

$ sensors | sed '/:$/{N;s/\n//;}' | awk -F: '$1=="CPU Temp (AMD)"{print $2}'
| cut -d"+" -f2 | sed -e 's/°C//' | cut -d"(" -f1 | sed 's/^[ \t]*//;s/[
\t]*$//'

Gives me a nice tidy '50'

And even:
$ CPU_Temp=`sensors | sed '/:$/{N;s/\n//;}' | awk -F: '$1=="CPU Temp
(AMD)"{print $2}' | cut -d "+" -f2 | sed -e 's/°C//' | cut -d "(" -f1 | sed
s/^[ \t]*//;s/[ \t]*$//'`
$ echo $CPU_Temp
50

But when I copy and paste this exact command into my shell script:
CPU_Temp=`sensors | sed '/:$/{N;s/\n//;}' | awk -F: '$1=="CPU Temp
(AMD)"{print $2}' | cut -d"+" -f2 | sed -e 's/°C//' | cut -d"(" -f1 | sed
s/^[ \t]*//;s/[ \t*$//'`

It loses some of the spaces around the commands and the whole thing comes
crumbling down :(

Anyway - duty calls, must be off to spend some quality time with the wife
before she put a hammer through all of my PCs.

If anyone can help out it'd be most appreciated :)



Relevant Pages