From owner-freebsd-questions@FreeBSD.ORG Thu Aug 14 12:28:35 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 3B78E37B401 for ; Thu, 14 Aug 2003 12:28:35 -0700 (PDT) Received: from remt19.cluster1.charter.net (remt19.cluster1.charter.net [209.225.8.29]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5F06543FE0 for ; Thu, 14 Aug 2003 12:28:34 -0700 (PDT) (envelope-from chowse@charter.net) Received: from [66.168.145.25] (HELO moe) by remt19.cluster1.charter.net (CommuniGate Pro SMTP 4.0.6) with ESMTP id 122983567 for freebsd-questions@freebsd.org; Thu, 14 Aug 2003 15:28:33 -0400 From: "Charles Howse" To: Date: Thu, 14 Aug 2003 14:28:21 -0500 Message-ID: <001101c3629a$3d1dbab0$04fea8c0@moe> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0012_01C36270.5447B2B0" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 In-Reply-To: <20030814125801.11b0c2d2.nospam@hiltonbsd.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal 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 19:28:35 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_0012_01C36270.5447B2B0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit > > 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. 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. ------=_NextPart_000_0012_01C36270.5447B2B0 Content-Type: application/octet-stream; name="daily_report.sh" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="daily_report.sh" #!/usr/local/bin/bash=0A= # Daily Report=0A= =0A= # Declare variables=0A= start_time=3D`date +%s`=0A= time1=3D`date +%R`=0A= month=3D`date +%b`=0A= day=3D`date +%e`=0A= =0A= # Cleanup files=0A= if [ -a /root/daily.log ] ; then=0A= rm /root/daily.log=0A= fi=0A= =0A= # Main report header=0A= echo "Daily Report for Larry for" `date '+%A, %B %d %Y'`"." >> = /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= echo >> /root/daily.log =0A= =0A= # OS header=0A= echo "Current Operating System" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= uname -sr >> /root/daily.log =0A= echo >> /root/daily.log =0A= =0A= # Uptime Header=0A= echo "Uptime" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= uptime >> /root/daily.log =0A= echo >> /root/daily.log=0A= =0A= # Crontab Header=0A= echo "Cron Jobs" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= crontab -l >> /root/daily.log =0A= echo >> /root/daily.log=0A= =0A= # Last Header=0A= echo "Logins today" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= last | grep "$month $day" >> /root/daily.log =0A= echo >> /root/daily.log=0A= =0A= # Superuser Header=0A= echo "Accounts with uid =3D 0 (Superusers)" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= awk -F: '( $3 =3D=3D 0 ) { print $1 }' /etc/passwd >> /root/daily.log =0A= echo >> /root/daily.log=0A= =0A= # /etc/passwd Header=0A= echo "Accounts that have a valid shell" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= cat /etc/passwd | egrep -v "("nologin"|"uucico"|"\#")" >> = /root/daily.log =0A= echo >> /root/daily.log=0A= =0A= # DF Header=0A= echo "Disk Free space" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= df -h >> /root/daily.log =0A= echo >> /root/daily.log=0A= =0A= # netstat Header=0A= echo "Netstat -an results" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= netstat -an >> /root/daily.log=0A= echo >> /root/daily.log=0A= =0A= # ifconfig=0A= echo "Status of network interfaces" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= ifconfig >> /root/daily.log=0A= echo >> /root/daily.log=0A= =0A= # Compute the elapsed time=0A= echo "Elapsed Time" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= echo "Report completed at:" `date +%R` >> /root/daily.log=0A= echo " Report begun at:" $time1 >> /root/daily.log=0A= end_time=3D`date +%s`=0A= et=3D`echo "scale=3D5 ; $end_time - $start_time" | bc`=0A= #if [ $et -lt 1 ] ; then=0A= # echo " Elapsed Time: less than 1 second" >> /root/daily.log=0A= #else=0A= echo " Elapsed Time: " $et "seconds" >> /root/daily.log=0A= #fi=0A= echo >> /root/daily.log=0A= =0A= # File Modification Date=0A= echo "Last modified" >> /root/daily.log=0A= echo "********************************************" >> /root/daily.log=0A= ls -l /root/bin/daily_report | cut -d" " -f9,10,11 >> /root/daily.log=0A= =0A= # Mail to Chalres=0A= cat /root/daily.log | mail -s "Daily Report from Larry" charles=0A= ------=_NextPart_000_0012_01C36270.5447B2B0--