I;m trying to fetch the laste temperature from a rrd database, with the follwing command:
[root@kroonen thgr228n.1f]# rrdtool fetch temp.rrd AVERAGE -r 600 -s -1min
timestamp temp
1196546040: 1.8300000000e+01
1196546100: nan
1196546160: nan
How do i get only the value 1.8300000+01 but as value 18,3 with scipt or cut, if it is under 10 degrees it must also work 9,90000+0 as 9,9
experience rrdtool fetch temp
- Snelvuur
- Forum Moderator
- Posts: 3156
- Joined: Fri Apr 06, 2007 11:01 pm
- Location: Netherlands
- Contact:
experience rrdtool fetch temp
I come as far as this:
awk 'BEGIN {printf "%.3f\n", 18.200000}'
This works pretty ok, but when there is a "+01" behind it, it doesn't work. It will count 1 to the output, dont know quickly how to solve that. Its bound to be possible in perl though.
Update:
printf %f `echo "1.8300000000e+01"|sed -e s/+//;`
Will give you 18.300000.. hope that helps.
// Erik (binkey.nl)
awk 'BEGIN {printf "%.3f\n", 18.200000}'
This works pretty ok, but when there is a "+01" behind it, it doesn't work. It will count 1 to the output, dont know quickly how to solve that. Its bound to be possible in perl though.
Update:
printf %f `echo "1.8300000000e+01"|sed -e s/+//;`
Will give you 18.300000.. hope that helps.
// Erik (binkey.nl)
experience rrdtool fetch temp
This is what I came up with:
perl -e '$a="1.8300000+01";$a=~s/\+/E/g;printf("%.2f\n",$a);'
Neil Cherry
Linux Home Automation
Author: Linux Smart Homes For Dummies
perl -e '$a="1.8300000+01";$a=~s/\+/E/g;printf("%.2f\n",$a);'
Neil Cherry
Linux Home Automation
Author: Linux Smart Homes For Dummies
experience rrdtool fetch temp
thanks for that one, the perl is vey nice, now I need to get the right line
i have aleady this
rrdtool fetch temp.rrd AVERAGE --start -2min --end -1min | awk '{print $2}'
with result
temp
1.6300000000e+01
1.6300000000e+01
nan
I need line 3 only, how can I awk the right line?
i have aleady this
rrdtool fetch temp.rrd AVERAGE --start -2min --end -1min | awk '{print $2}'
with result
temp
1.6300000000e+01
1.6300000000e+01
nan
I need line 3 only, how can I awk the right line?
experience rrdtool fetch temp
Can it with tail of grep?? anu ideas are welcome
- Snelvuur
- Forum Moderator
- Posts: 3156
- Joined: Fri Apr 06, 2007 11:01 pm
- Location: Netherlands
- Contact:
experience rrdtool fetch temp
perhaps with "head" .. but check google this should not be that hard. If it doesn't work i'll look further into it. I'am trying to get some zenah sql's now, but i can allready tell you that response times are 10x quicker..
// Erik (binkey.nl)
// Erik (binkey.nl)
experience rrdtool fetch temp
Well finally I have a script, maybe not so nice written but it gives nice output
#!/bin/sh
/usr/bin/rrdtool fetch temp.rrd AVERAGE --start -120 --end -60 | awk '{print $2}' | grep 0 > test
read=`head -n1 test`
printf %f `echo $read|sed -e s/+//;` > test
cat test | cut -b 1,2,3,4,5
#!/bin/sh
/usr/bin/rrdtool fetch temp.rrd AVERAGE --start -120 --end -60 | awk '{print $2}' | grep 0 > test
read=`head -n1 test`
printf %f `echo $read|sed -e s/+//;` > test
cat test | cut -b 1,2,3,4,5
experience rrdtool fetch temp
kroon040
This is what I'm currently using to do something similar:
Please consider that I'm fetching the average temp form the last 30min from an rrd database that store several resolutions (5min, 30min, etc)
$ctime = time;
$rrdres = 1800;
$etime = (int($ctime/$rrdres))*$rrdres-1;
$stime = (($etime)-1799);
my ($start,$step,$names,$array) =
RRDs::fetch("$RRD/temp.rrd", "AVERAGE",
"-r", "$rrdres", "-s", "$stime", "-e", "$etime");
I hope this help
Asmodeo
This is what I'm currently using to do something similar:
Please consider that I'm fetching the average temp form the last 30min from an rrd database that store several resolutions (5min, 30min, etc)
$ctime = time;
$rrdres = 1800;
$etime = (int($ctime/$rrdres))*$rrdres-1;
$stime = (($etime)-1799);
my ($start,$step,$names,$array) =
RRDs::fetch("$RRD/temp.rrd", "AVERAGE",
"-r", "$rrdres", "-s", "$stime", "-e", "$etime");
I hope this help
Asmodeo