Using bc in bash script

Charles Howse chowse at charter.net
Thu Aug 14 12:28:35 PDT 2003


> > 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 at 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.
 
First, let me thank everyone who responded to my *first* post to this
list.
This seems like a really good 'community', I'm gonna hang around.  ;-)

Now, I've written many bash scripts in RedHat, and FreeBSD's set of
commands *is* just a little bit different, but I'm gonna need a little
shove in the right direction here.

I'm not asking for anyone to re-write anything for me, just a friendly
suggestion as to exactly to implement the 'time' command so that the
file that my daily_report script generates includes the elapsed time in
hundredths on the proper line.

I've attached the script for reference. 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: daily_report.sh
Type: application/octet-stream
Size: 2996 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20030814/72a31cd8/daily_report.obj


More information about the freebsd-questions mailing list