Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Aug 2003 12:58:01 -0500
From:      Stephen Hilton <nospam@hiltonbsd.com>
To:        Jez Hancock <jez.hancock@munk.nu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Using bc in bash script
Message-ID:  <20030814125801.11b0c2d2.nospam@hiltonbsd.com>
In-Reply-To: <20030814173425.GA78559@users.munk.nu>
References:  <20030814115313.2707cb21.nospam@hiltonbsd.com> <003001c36287$2a2a7b40$04fea8c0@moe> <20030814122334.0a05ab4b.nospam@hiltonbsd.com> <20030814173425.GA78559@users.munk.nu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 14 Aug 2003 18:34:25 +0100
Jez Hancock <jez.hancock@munk.nu> wrote:

> On Thu, Aug 14, 2003 at 12:23:34PM -0500, Stephen Hilton wrote:
> > On Thu, 14 Aug 2003 12:11:55 -0500
> > "Charles Howse" <chowse@charter.net> wrote:
> > 
> > > > Charles,
> > > > 
> > > > This will set bc precision to 5 decimal places:
> > > > 
> > > > et=`echo "scale=5 ; $end_time - $start_time" | bc`
> > > 
> > > Ohhh, I was really hoping on that one...but no, it still reports 0
> > > seconds.
> > 
> > 
> > Sorry I jumped the gun there, the scale is needed for this to work 
> > but the "date +%s" willonly resolve into whole seconds after reading 
> > the date man page.
> > 
> > I sure am curious as to how to solve this also, the /usr/bin/time 
> > command man page says this:
> > 
> > -----------------snip------------------
> > DESCRIPTION
> >      The time utility executes and times the specified utility.  After the
> >      utility finishes, time writes to the standard error stream, (in seconds):
> >      the total time elapsed, the time used to execute the utility process and
> >      the time consumed by system overhead.
> > -----------------snip------------------
> > 
> > So that looks like seconds only also.
> The precision is in hundredths of a second as I understand it from
> playing with time(!):
> 
> #!/bin/sh
> time_file=tmp.time
> time="time -a -o $time_file"
> $time cat /var/log/messages >/dev/null 2>&1
> $time cat /var/log/maillog >/dev/null 2>&1
> awk '{sum+=$1}END{print sum}' $time_file
> rm $time_file
> 
> which outputs:
> 
> [18:34:03] munk@users /home/munk# sh tmp.sh
> 0.01
> 
> This simple script just times each cat command and appends the output from
> time to the $time_file, then prints out the sum of the first columns of
> the time outputs found in the time file. 
> 
> Just an idea.
> -- 

Jez,

Your shell script works fine for me, resolving to 100th's of a second.

Looks like a good answer for Charles :-)

I still am wondering why the date command does not have a format 
string for seconds (down to 100th's) like "+%ss" and also why 
the time command stops at 100th's when other programs resolve 
time to 5 or 6 decimal places ?

Thanks for sharing the info,

Stephen Hilton
nospam@hiltonbsd.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030814125801.11b0c2d2.nospam>