Date: Thu, 14 Aug 2003 14:28:21 -0500 From: "Charles Howse" <chowse@charter.net> To: <freebsd-questions@freebsd.org> Subject: RE: Using bc in bash script Message-ID: <001101c3629a$3d1dbab0$04fea8c0@moe> In-Reply-To: <20030814125801.11b0c2d2.nospam@hiltonbsd.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001101c3629a$3d1dbab0$04fea8c0>