From owner-freebsd-questions@FreeBSD.ORG Thu Aug 14 14:23: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 54FFA37B401 for ; Thu, 14 Aug 2003 14:23:35 -0700 (PDT) Received: from remt27.cluster1.charter.net (remt27.cluster1.charter.net [209.225.8.37]) by mx1.FreeBSD.org (Postfix) with ESMTP id 71B6F43FE3 for ; Thu, 14 Aug 2003 14:23:34 -0700 (PDT) (envelope-from chowse@charter.net) Received: from [66.168.145.25] (HELO moe) by remt27.cluster1.charter.net (CommuniGate Pro SMTP 4.0.6) with ESMTP id 121520626 for freebsd-questions@freebsd.org; Thu, 14 Aug 2003 17:23:33 -0400 From: "Charles Howse" To: Date: Thu, 14 Aug 2003 16:23:21 -0500 Message-ID: <001e01c362aa$4d0cc230$04fea8c0@moe> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit 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 21:23:35 -0000 OK, I've been playing with the time command to get the elapsed time of my daily_report script reported in 2 decimal places. If I do: # \time -ha ~/daily.log ~/bin/daily_report (append output of time to ~/daily.log) I get: Time: /root/daily.log permission denied (time output) If I do: # chmod 666 daily.log # \time -ha ~/daily.log ~/bin/daily_report (append output of time to ~/daily.log) I get: Time: /root/daily.log permission denied (time output) If I do: # \time -ho ~/tmp.time ~/bin/daily_report That works OK The problem with all of this is that time must wait for the daily_report script to finish before it writes tmp.time. By then, in it's existing form, daily_report has already mailed daily.log to charles. I'm gonna hafta re-write and re-arrange some things to make this work properly. I don't object to that in principle, but there must be a more elegant way to do this. For reference: ---------------------------------------------- #!/usr/local/bin/bash # Daily Report # Declare variables start_time=`date +%s` time1=`date +%R` month=`date +%b` day=`date +%e` # Cleanup files if [ -a /root/daily.log ] ; then rm /root/daily.log fi # Main report header echo "Daily Report for Larry for" `date '+%A, %B %d %Y'`"." >> /root/daily.log echo "********************************************" >> /root/daily.log echo >> /root/daily.log # OS header echo "Current Operating System" >> /root/daily.log echo "********************************************" >> /root/daily.log uname -sr >> /root/daily.log echo >> /root/daily.log # Uptime Header echo "Uptime" >> /root/daily.log echo "********************************************" >> /root/daily.log uptime >> /root/daily.log echo >> /root/daily.log # Crontab Header echo "Cron Jobs" >> /root/daily.log echo "********************************************" >> /root/daily.log crontab -l >> /root/daily.log echo >> /root/daily.log # Last Header echo "Logins today" >> /root/daily.log echo "********************************************" >> /root/daily.log last | grep "$month $day" >> /root/daily.log echo >> /root/daily.log # Superuser Header echo "Accounts with uid = 0 (Superusers)" >> /root/daily.log echo "********************************************" >> /root/daily.log awk -F: '( $3 == 0 ) { print $1 }' /etc/passwd >> /root/daily.log echo >> /root/daily.log # /etc/passwd Header echo "Accounts that have a valid shell" >> /root/daily.log echo "********************************************" >> /root/daily.log cat /etc/passwd | egrep -v "("nologin"|"uucico"|"\#")" >> /root/daily.log echo >> /root/daily.log # DF Header echo "Disk Free space" >> /root/daily.log echo "********************************************" >> /root/daily.log df -h >> /root/daily.log echo >> /root/daily.log # netstat Header echo "Netstat -an results" >> /root/daily.log echo "********************************************" >> /root/daily.log netstat -an >> /root/daily.log echo >> /root/daily.log # ifconfig echo "Status of network interfaces" >> /root/daily.log echo "********************************************" >> /root/daily.log ifconfig >> /root/daily.log echo >> /root/daily.log # Compute the elapsed time echo "Elapsed Time" >> /root/daily.log echo "********************************************" >> /root/daily.log echo "Report completed at:" `date +%R` >> /root/daily.log echo " Report begun at:" $time1 >> /root/daily.log end_time=`date +%s` et=`echo $end_time - $start_time | bc` if [ $et -lt 1 ] ; then echo " Elapsed Time: less than 1 second" >> /root/daily.log else echo " Elapsed Time: " $et "seconds" >> /root/daily.log fi echo >> /root/daily.log # File Modification Date echo "Last modified" >> /root/daily.log echo "********************************************" >> /root/daily.log ls -l /root/bin/daily_report | cut -d" " -f9,10,11 >> /root/daily.log # Mail to Chalres cat /root/daily.log | mail -s "Daily Report from Larry" charles