From owner-freebsd-questions@FreeBSD.ORG Thu Aug 14 10:34:28 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 31CE337B401 for ; Thu, 14 Aug 2003 10:34:28 -0700 (PDT) Received: from munk.nu (213-152-51-194.dsl.eclipse.net.uk [213.152.51.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7E2E843F85 for ; Thu, 14 Aug 2003 10:34:27 -0700 (PDT) (envelope-from munk@munk.nu) Received: from munk by munk.nu with local (Exim 4.20) id 19nLzV-000Kk0-L7 for freebsd-questions@freebsd.org; Thu, 14 Aug 2003 18:34:25 +0100 Date: Thu, 14 Aug 2003 18:34:25 +0100 From: Jez Hancock To: freebsd-questions@freebsd.org Message-ID: <20030814173425.GA78559@users.munk.nu> Mail-Followup-To: freebsd-questions@freebsd.org References: <20030814115313.2707cb21.nospam@hiltonbsd.com> <003001c36287$2a2a7b40$04fea8c0@moe> <20030814122334.0a05ab4b.nospam@hiltonbsd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030814122334.0a05ab4b.nospam@hiltonbsd.com> User-Agent: Mutt/1.4.1i Sender: User Munk Subject: Re: Using bc in bash script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2003 17:34:28 -0000 On Thu, Aug 14, 2003 at 12:23:34PM -0500, Stephen Hilton wrote: > On Thu, 14 Aug 2003 12:11:55 -0500 > "Charles Howse" 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 http://www.munk.nu/