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

This is a discussion on [rrd-users] Re: Help with Bash script to calc end-time in multiples of 300 ? within the RRD Users forums, part of the Networking and Network Related category; On Sat, Nov 18, 2006 at 09:32:15AM +0000, Simon Hobson wrote: > Rob Conway wrote: > > >...


Go Back   Usenet Forums > Networking and Network Related > RRD Users

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-18-2006
Alex van den Bogaerdt
 
Posts: n/a
Default [rrd-users] Re: Help with Bash script to calc end-time in multiples of 300 ?

On Sat, Nov 18, 2006 at 09:32:15AM +0000, Simon Hobson wrote:
> Rob Conway wrote:
>
> >I just use "date +%s" to get the unix time but how can I easily
> >round this value ?

>
> 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.


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)

I use a hardcoded path, to avoid PATH search (more work, more cpu
cycles needed, more time!).

Time formatting works, so you can add '+%F %T' to the command and
get a nicer format:

/bin/date -d 19700101\ 00:00\ +0000\ ${etime}sec +%F\ %T

To get it into a variable, to be used in your graph script:

printedtime=$(/bin/date -d 19700101\ 00:00\ +0000\ ${etime}sec +%F\ %T)
printedtime=$(/bin/date -d "19700101 00:00 +0000 ${etime}sec" +"%F %T")



HTH
--
Alex van den Bogaerdt
http://www.vandenbogaerdt.nl/rrdtool/

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0