[rrd-users] start time

Simon Hobson linux at thehobsons.co.uk
Fri Jul 1 12:36:10 CEST 2011


fadwa salam wrote:

>the problem is ,when I do the subtraction of this period to the 
>present timestamp does not work .
>
>$rrdtool fetch power.rrd AVERAGE -s 1h
>
>end=$(date +%s)
>time=$2 =1h
>let "start=($end-$time)"
>
>ERROR: start time: unparsable trailing text: '...h'
>   start time: There should be number after '-'

Assuming you are using Bash, then use the shell arithmetic to do a 
subtraction like this :

start=$(( $end - $time ))

But, and this case up recently, your start and end times must be an 
exact integral multiple of the resolution period you want. So if you 
want 5 minute resolution data, then your start and end times must be 
an integral multiple of 300s.

So (again in Bash) :

end=`date +%s`
time=3600
period=300

end=$(( ( ${end} / ${period} ) * ${period} ))
time=$(( ( ${time} / ${period} ) * ${period} ))
start=$(( ${end} - ${time} ))


-- 
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.



More information about the rrd-users mailing list