RE: Using bc in bash script

2003-08-14 Thread Charles Howse
 On Thu, Aug 14, 2003 at 10:46:45AM -0500, Charles Howse wrote:
  Hello List,
  
  I've migrated from Redhat Linux 9 to FreeBSD 4.8-RELEASE, 
 character mode
  - no gui.
  
  I'm trying to calculate the number of seconds between 
 $start_time and
  $end_time in a bash script.
  
  Start_time=`date +%s` # Seconds past midnight at start of script
  [ do lots of stuff ]
  End_time=`date +%s`   # Seconds past midnight at end of script
  
  Then I want to: et=`bc $end_time - $start_time` to get the number of
  seconds or fractions of seconds elapsed.
 How about:
 
 et=`echo $end_time - $start_time | bc`

Hi Jez, thanks for the reply!

As my daughter would say, Well, DUHHH!
That worked fine, it reported 0 seconds.
Can I refine it to give me something like: .784 seconds?


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Richard Tobin
 I'm trying to calculate the number of seconds between $start_time and
 $end_time in a bash script.

Bash has built-in integer arithmetic:

  et=$[End_time - Start_time]

-- Richard
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


RE: Using bc in bash script

2003-08-14 Thread Charles Howse
 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.
Maybe there's something in the script itself that's messing this up.
Here is the entire script:



#!/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 scale=5 ; $end_time - $start_time | bc`
echoElapsed Time:  $et seconds  /root/daily.log
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 Charles
cat /root/daily.log | mail -s Daily Report from Larry charles


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Jez Hancock
On Thu, Aug 14, 2003 at 11:08:21AM -0500, Charles Howse wrote:
  On Thu, Aug 14, 2003 at 10:46:45AM -0500, Charles Howse wrote:
   Hello List,
   
   I've migrated from Redhat Linux 9 to FreeBSD 4.8-RELEASE, 
  character mode
   - no gui.
   
   I'm trying to calculate the number of seconds between 
  $start_time and
   $end_time in a bash script.
   
   Start_time=`date +%s` # Seconds past midnight at start of script
   [ do lots of stuff ]
   End_time=`date +%s`   # Seconds past midnight at end of script
   
   Then I want to: et=`bc $end_time - $start_time` to get the number of
   seconds or fractions of seconds elapsed.
  How about:
  
  et=`echo $end_time - $start_time | bc`
 
 Hi Jez, thanks for the reply!
 
 As my daughter would say, Well, DUHHH!
:)

 That worked fine, it reported 0 seconds.
Hah, computers are just too damn fast :)

 Can I refine it to give me something like: .784 seconds?
You could use 'time' perhaps to time whatever it is you're timing - I'm
not overly familiar with the time(1) command though, best to check the man
page :)

-- 
Jez

http://www.munk.nu/
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Kirk Strauser
At 2003-08-14T16:45:56Z, Charles Howse [EMAIL PROTECTED] writes:

 I think this whole thing is dependent on the fact that `date +%s` reports
 integers.

As his daughter says, DUUUH!  I only saw the $end_time and $start_time
variables, and not their origins.  I'll go back to lurking now.  :)
-- 
Kirk Strauser


pgp0.pgp
Description: PGP signature


Re: Using bc in bash script

2003-08-14 Thread Joshua Oreman
On Thu, Aug 14, 2003 at 12:58:01PM -0500 or thereabouts, Stephen Hilton wrote:
 On Thu, 14 Aug 2003 18:34:25 +0100
 Jez Hancock [EMAIL PROTECTED] wrote:
 
  On Thu, Aug 14, 2003 at 12:23:34PM -0500, Stephen Hilton wrote:
   On Thu, 14 Aug 2003 12:11:55 -0500
   Charles Howse [EMAIL PROTECTED] 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 21
  $time cat /var/log/maillog /dev/null 21
  awk '{sum+=$1}END{print sum}' $time_file
  rm $time_file
  
  which outputs:
  
  [18:34:03] [EMAIL PROTECTED] /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,
 
 Your shell script works fine for me, resolving to 100th's of a second.
 
 Looks like a good answer for Charles :-)
 
 I still am wondering why the date command does not have a format 
 string for seconds (down to 100th's) like +%ss and also why 
 the time command stops at 100th's when other programs resolve 
 time to 5 or 6 decimal places ?

All the good % things are taken :-)

Here are three ways of doing it:

% cat  gettimeofday.c 'EOF'
#include stdio.h
#include sys/time.h

int main() {
struct timeval tv;
struct timezone unused;

gettimeofday (tv, unused);

printf (%li.%li\n, tv.tv_sec, tv.tv_usec);
return 0;
}
EOF
% cc -o gettimeofday gettimeofday.c
% ./gettimeofday; echo hello, world; ./gettimeofday
1060886109.667054
hello, world
1060886109.687446

% gettimeofday() {
 perl -MTime::HiRes=gettimeofday -e '($sec, $usec) = gettimeofday(); print $sec, 
 ., $usec, \n'
 }
% gettimeofday; echo hello, world; gettimeofday
1060886661.274900
hello, world
1060886661.313071

% gettimeofday2() {
 perl 'EOF'
 $now = pack (LL, ());
 syscall (116, $now, 0) != 1 or die gettimeofday: $!;
 @now = unpack (LL, $now);
 print $now[0], ., $now[1], \n;
 EOF
 }
% gettimeofday2; echo hello, world; gettimeofday2
1060887546.767676
hello, world
1060887546.938097

% rm gettimeofday gettimeofday.c
% unset gettimeofday
% unset gettimeofday2

The first one (the C program) works anywhere but you have to compile it.
The second one (perl -MTime::HiRes...) works if you have either Time::HiRes from CPAN 
or perl=5.8.
The third one (perl ... syscall 116 ...) is specific to FreeBSD/i386 and a bit slower, 
but it works.

HTH

-- Josh

 
 Thanks for sharing the info,
 
 Stephen Hilton
 [EMAIL PROTECTED]
 ___
 [EMAIL PROTECTED] mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Stephen Hilton
On Thu, 14 Aug 2003 12:11:55 -0500
Charles Howse [EMAIL PROTECTED] 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.

A quick browse through man sh and man bash look like their 
builtin time commands also resolve to seconds.


Curiousy,

Stephen Hilton
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Kirk Strauser
At 2003-08-14T16:08:21Z, Charles Howse [EMAIL PROTECTED] writes:

 Can I refine it to give me something like: .784 seconds?

Use bc -l instead of bc.  That should do it.
-- 
Kirk Strauser


pgp0.pgp
Description: PGP signature


RE: Using bc in bash script

2003-08-14 Thread Charles Howse
  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 21
  $time cat /var/log/maillog /dev/null 21
  awk '{sum+=$1}END{print sum}' $time_file
  rm $time_file
  
  which outputs:
  
  [18:34:03] [EMAIL PROTECTED] /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. 


daily_report.sh
Description: Binary data
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Jez Hancock
On Thu, Aug 14, 2003 at 10:46:45AM -0500, Charles Howse wrote:
 Hello List,
 
 I've migrated from Redhat Linux 9 to FreeBSD 4.8-RELEASE, character mode
 - no gui.
 
 I'm trying to calculate the number of seconds between $start_time and
 $end_time in a bash script.
 
 Start_time=`date +%s` # Seconds past midnight at start of script
 [ do lots of stuff ]
 End_time=`date +%s`   # Seconds past midnight at end of script
 
 Then I want to: et=`bc $end_time - $start_time` to get the number of
 seconds or fractions of seconds elapsed.
How about:

et=`echo $end_time - $start_time | bc`

-- 
Jez

http://www.munk.nu/
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


RE: Using bc in bash script

2003-08-14 Thread Charles Howse
I received this msg a short time ago:

Antigen for Exchange found daily_report.sh matching =*.sh file filter.
The file is currently Removed.  The message, RE: Using bc in bash
script,
was
sent from Charles Howse  and was discovered in IMC Queues\Inbound
located at mcglinchey/NewOrleans/NOLA.



I hope ANTIGEN_NOLA [EMAIL PROTECTED] is just a server on
the way to the freebsd-questions server!
It'd be sacrelegious for a FreeBSD list server to run M$ Exchange!!! ;-)

If you didn't get my attachment and need it for reference, reply and
I'll post it inline.


Thanks,
Charles


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


RE: Using bc in bash script

2003-08-14 Thread Charles Howse
   Sorry I jumped the gun there, the scale is needed for 
 this to work 

Not a problem, thanks for working with me!

  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 21
  $time cat /var/log/maillog /dev/null 21
  awk '{sum+=$1}END{print sum}' $time_file
  rm $time_file
  
  which outputs:
  
  [18:34:03] [EMAIL PROTECTED] /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,
 
 Your shell script works fine for me, resolving to 100th's of a second.
 
 Looks like a good answer for Charles :-)
 
 I still am wondering why the date command does not have a format 
 string for seconds (down to 100th's) like +%ss and also why 
 the time command stops at 100th's when other programs resolve 
 time to 5 or 6 decimal places ?
 
 Thanks for sharing the info,

Yes, thanks very much!
I'll try that as soon as I finish my break from hanging window blinds
for my daughter. (ick!)


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Kirk Strauser
At 2003-08-14T17:58:01Z, Stephen Hilton [EMAIL PROTECTED] writes:

 I still am wondering why the date command does not have a format string
 for seconds (down to 100th's) like +%ss and also why the time command
 stops at 100th's when other programs resolve time to 5 or 6 decimal places?

My guess is that its margin of error, given the nondeterministic influence
of a few forks etc., is probably too big to give a more precise answer.
-- 
Kirk Strauser


pgp0.pgp
Description: PGP signature


RE: Using bc in bash script

2003-08-14 Thread Alexander Haderer
At 11:45 14.08.2003 -0500, Charles Howse wrote:
  Can I refine it to give me something like: .784 seconds?

 Use bc -l instead of bc.  That should do it.
No, that still gives 0 seconds.

I think this whole thing is dependent on the fact that `date +%s`
reports integers.
I'm still interested in something like .874 seconds, but for the time
being, I'll just use an if..then..else to say less than 1 second or
the actual number of seconds.
I've looked at the time command suggested by Jez, haven't tried it yet.
Note the trap: shell's builtin time command differs somewhat from 
installed /usr/bin/time!

man time
man builtin
man your_shell
Alexander

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


RE: Using bc in bash script

2003-08-14 Thread Charles Howse
  Can I refine it to give me something like: .784 seconds?
 
 Use bc -l instead of bc.  That should do it.

No, that still gives 0 seconds.

I think this whole thing is dependent on the fact that `date +%s`
reports integers.

I'm still interested in something like .874 seconds, but for the time
being, I'll just use an if..then..else to say less than 1 second or
the actual number of seconds.

I've looked at the time command suggested by Jez, haven't tried it yet.

Gzz, why don't they include some *SIMPLE* examples in the man pages?
Not everybody has a degree in Advanced Calculus and works as a C++
programmer.  ;-)


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Stephen Hilton
On Thu, 14 Aug 2003 11:08:21 -0500
Charles Howse [EMAIL PROTECTED] wrote:

  On Thu, Aug 14, 2003 at 10:46:45AM -0500, Charles Howse wrote:
   Hello List,
   
   I've migrated from Redhat Linux 9 to FreeBSD 4.8-RELEASE, 
  character mode
   - no gui.
   
   I'm trying to calculate the number of seconds between 
  $start_time and
   $end_time in a bash script.
   
   Start_time=`date +%s` # Seconds past midnight at start of script
   [ do lots of stuff ]
   End_time=`date +%s`   # Seconds past midnight at end of script
   
   Then I want to: et=`bc $end_time - $start_time` to get the number of
   seconds or fractions of seconds elapsed.
  How about:
  
  et=`echo $end_time - $start_time | bc`
 
 Hi Jez, thanks for the reply!
 
 As my daughter would say, Well, DUHHH!
 That worked fine, it reported 0 seconds.
 Can I refine it to give me something like: .784 seconds?

Charles,

This will set bc precision to 5 decimal places:

et=`echo scale=5 ; $end_time - $start_time | bc`


Regards,

Stephen Hilton
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Stephen Hilton
On Thu, 14 Aug 2003 18:34:25 +0100
Jez Hancock [EMAIL PROTECTED] wrote:

 On Thu, Aug 14, 2003 at 12:23:34PM -0500, Stephen Hilton wrote:
  On Thu, 14 Aug 2003 12:11:55 -0500
  Charles Howse [EMAIL PROTECTED] 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 21
 $time cat /var/log/maillog /dev/null 21
 awk '{sum+=$1}END{print sum}' $time_file
 rm $time_file
 
 which outputs:
 
 [18:34:03] [EMAIL PROTECTED] /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,

Your shell script works fine for me, resolving to 100th's of a second.

Looks like a good answer for Charles :-)

I still am wondering why the date command does not have a format 
string for seconds (down to 100th's) like +%ss and also why 
the time command stops at 100th's when other programs resolve 
time to 5 or 6 decimal places ?

Thanks for sharing the info,

Stephen Hilton
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Alexander Haderer
At 11:35 14.08.2003 -0500, Kirk Strauser wrote:
At 2003-08-14T16:08:21Z, Charles Howse [EMAIL PROTECTED] writes:

 Can I refine it to give me something like: .784 seconds?

Use bc -l instead of bc.  That should do it.
Yes, but not in the context mentioned before:

   Start_time=`date +%s` # Seconds past midnight at start of script
   [ do lots of stuff ]
   End_time=`date +%s`   # Seconds past midnight at end of script
et=`echo $end_time - $start_time | bc -l`

Here bc -l will not really help, because date +%s returns whole seconds :-(

BTW: %s are seconds since epoch

Alexander

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using bc in bash script

2003-08-14 Thread Jez Hancock
On Thu, Aug 14, 2003 at 12:23:34PM -0500, Stephen Hilton wrote:
 On Thu, 14 Aug 2003 12:11:55 -0500
 Charles Howse [EMAIL PROTECTED] 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 21
$time cat /var/log/maillog /dev/null 21
awk '{sum+=$1}END{print sum}' $time_file
rm $time_file

which outputs:

[18:34:03] [EMAIL PROTECTED] /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/
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


RE: Using bc in bash script

2003-08-14 Thread Charles Howse
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
echoElapsed Time: less than 1 second  /root/daily.log
else
echoElapsed 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


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]