On Sun, 13 Sep 2009, Matthew J. Roth wrote:

> Here's a Bash script that will do what you're looking for.  If you 
> redirect the output to a file it will only contain the queue_log records 
> in the date range from start_epoch to end_epoch.  Note that it may take 
> a while to complete, depending on the size of your queue_log.
>
> --- Start getdates_ql
> ----------------------------------------------------------
> #!/bin/bash
>
> start_epoch=`date -d 'Sep 9 2009 00:00:00' +'%s'`
> end_epoch=`date -d 'Sep 12 2009 23:59:59' +'%s'`
>
> while read line; do
>    epoch=`echo $line | cut -d '|' -f 1`
>
>    if [ $epoch -ge $start_epoch -a $epoch -le $end_epoch ]; then
>      echo $line
>    fi
> done < /var/log/asterisk/queue_log
>
> exit 0
>
> --- End getdates_ql
> ------------------------------------------------------------

You can speed up this script by nearly an order of magnitude by extracting 
the epoch more efficiently. The method in this script creates 3 processes 
for every line in the queue log. You can replace that single step with:

        epoch=${line:0:10}

Since it is unlikely that any of us will live to see an eleven digit epoch 
(about 300 years from now), this should be an acceptable simplification. 
If you plan on living that long, you could to a substring to find the 
pipe, blah, blah, blah. The boost is because you aren't spending most of 
your time creating processes.

If this is a function you do frequently, re-coding in C is trivial and 
even more significant -- reducing the run-time on my over-priced and 
under-powered Fit-PC (500MHZ AMD Geode) from 82 seconds to 0.03 seconds 
(2,700 times faster) for a 10,000 line queue file.

        -dt-ext::sedwards:~$ time ./getdates-ql >/dev/null
        real    1m22.234s
        user    0m30.027s
        sys     0m51.467s

        -dt-ext::sedwards:~$ time ./getdates-ql2 >/dev/null
        real    0m10.207s
        user    0m9.921s
        sys     0m0.148s

        -dt-ext::sedwards:~$ time ./getdates-qlc >/dev/null
        real    0m0.033s
        user    0m0.029s
        sys     0m0.004s

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       [email protected]      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000

_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

AstriCon 2009 - October 13 - 15 Phoenix, Arizona
Register Now: http://www.astricon.net

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to