BB Unix Network Monitor - Message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: {bb} Timing a script



Hi,

There's also a nice command called "time".

The following compound command runs script.sh with time
and then forwards the output to awk for further processing.
The parentheses and 2>&1 redirection are important.

  TIME=`( time script.sh ) 2>&1 | awk ' $1 == "real" { print $2 } '`

Awk then picks the "real" time line from the output of "time script.sh".
You'll get a result like this: TIME=0m0.01s

You are probably only interested in minutes. Hence:

  TIME=`( time script.sh ) 2>&1 | awk ' $1 == "real" { print $2 } ' | sed
's/m.*//g'`

Next you'll want to set the color:

  test "$TIME" -gt "$YELLOW_LEVEL" && COLOR=yellow
  test "$TIME" -gt "$RED_LEVEL" && COLOR=red

You might wonder why I quoted numeric variables.
Reason: In case (when) something unexpected happens and TIME is left empty,
there will be a red warning instead of an error message that could go
undetected:
$ test "" -gt 0
$ echo  $?
1
$ test -gt 0
/bin/ksh: test: argument expected




> -----Original Message-----
> From: a m crowe [mailto:a.m.crowe@durham.ac.uk]
> Sent: 18. helmikuuta 2005 13:34
> To: bb@bb4.com
> Subject: {bb} Timing a script
> 
> 
> Hello,
> 
> I have a script which does a test imap procedure but I would 
> like BB to 
> time how long this procedure takes and alert me if it takes 
> too long, is 
> this possible in BB and any pointers in the right direction would be 
> great. I am using 1.9e.
> 
> thanks
> -- 
> Andrew Crowe
> 
> 
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=
> To unsubscribe from this list, or to subscribe to the bb-digest list
> send e-mail to mailto:majordomo@bb4.com with unsubscribe bb -and/or-
> subscribe bb-digest in the BODY of the message.
> 
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=
To unsubscribe from this list, or to subscribe to the bb-digest list
send e-mail to mailto:majordomo@bb4.com with unsubscribe bb -and/or-
subscribe bb-digest in the BODY of the message.


Home | Main Index | Thread Index