On 25.03.10 06:56, Michael Abbott wrote:
On Wed, 24 Mar 2010, Cathey, Jim wrote:
A shell script?

        while :; do
                read LINE
                echo `date`: $LINE
        done<ttydev>logfile
Better:

        while read -r; do
            echo "$(date): $REPLY"
         done<ttydev>logfile


If you use `read -r` you get the raw line, it's sensible to exit the loop
on end of input, and I don't understand why anybody still uses backticks
for command line sub-shells!

Hi

Thanks a lot. It works a treat. Here is my current script:

while read -r; do
    echo "[$(date)]: $REPLY"
done </dev/ttyUSB0 >>/usb/BigDrive/CurrentCost/CurrentCost.log

I used >> for the output to append the file rather then replace. This script is supposed to be always on,
I will start it automatically (probably in rc.syinit).

I have one more problem at the moment the data sets are separated by 0x0D 0x0A (carriage return and new line).
This means I get:

[Thu Mar 25 16:41:56 NZST 2010]: <msg><src>CC1 ... 000</watts></ch1></msg>
[Thu Mar 25 16:41:56 NZST 2010]:
[Thu Mar 25 16:41:59 NZST 2010]: <msg><src>CC1 ... </watts></ch3></msg>
[Thu Mar 25 16:41:59 NZST 2010]:


The second empty looking line contains the 0x0A.

Is there an easy way to disregard lines that contain only control characters or filter the text?

Regards
Mike


_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to