[rrd-users] Re: Help with Bash script to calc end-time in multiples of 300 ?

Simon Hobson linux at thehobsons.co.uk
Sun Nov 19 11:40:56 MET 2006

Alex van den Bogaerdt wrote:

>  > etime=`date +%s`
>>  step=300
>>  etime=$(( ${etime} - ( ${etime} % ${step} ) ))
>etime=$(( ${etime} / ${step} * ${step}  ))
>is 10% faster, at least on my system. I tried this by looping 100,000
>times doing those calculations, several runs.  Bash uses integer
>calculations, and my sequence saves a calculation internally.

Fair enough.

>Printing the value can be done using perl, but unless you're going to
>use perl for other purposes as well you are better off with gnu-date.
>This runs in 44% of the time needed for starting perl:
>/bin/date -d 19700101\ 00:00\ +0000\ ${etime}sec
>It means: the unix epoch (19700101 00:00, timezone UTC) and then
>${etime} seconds further in time (so: reverse of date +%s)

Sneeky ! I'd never have thought of that.

Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://lists.ee.ethz.ch/rrd-users
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi

More information about the rrd-users mailing list