Help with script

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

Post Reply
baobab
Junior Boarder
Junior Boarder
Posts: 37
Joined: Sat Dec 25, 2010 11:00 pm

Help with script

Post by baobab »

Hello,

I need some help solving a head scratcher. I am trying to run a custom script as an event in Meteobridge - Raspberry Pi edition. When I run it from the OpenWRT command line it works as intended - i.e the value of "$a" is published via mqtt (and when echo is uncommented the wind0 values print as expected). When I run it as an event from inside the Meteobridge application, the value published via mqtt is blank. It would appear that no data was received from "nc 127.0.0.1 5556" to be parsed and then assigned to $a. Here is the script:

Code: Select all

#!/bin/sh

while read -r a b c d e; do
     #echo "a=$a, b=$b, c=$c, d=$d, e=$e"
     mosquitto_pub -h 192.168.1.120 -t "test/test" -m "$a"
done <<EOF     
$(nc 127.0.0.1 5556 2>&1 | awk -F '[[:blank:]]+wind0[[:blank:]]+' 'NF>1{print $2}')
EOF
Here is another, easier to understand version of the same script.

Code: Select all

#!/bin/sh
#
### MQTT Test Script
#
nc 127.0.0.1 5556 2>&1 | awk -F '[[:blank:]]+wind0[[:blank:]]+' 'NF>1{print $2}' |
while read -r a b c d e; do
     #echo "a=$a, b=$b, c=$c, d=$d, e=$e"
     mosquitto_pub -h 192.168.1.120 -t "test/test" -m "$a"
done

As the one shown above it, it works as intended if executed from the command line as

Code: Select all

root@MeteoBridge:/tmp/mnt/data/scripts# ash mqtt_test.sh
but fails to work if run as an event. Some additional troubleshooting indicates that

Code: Select all

nc 127.0.0.1 5556 2>&1 | awk -F '[[:blank:]]+wind0[[:blank:]]+' 'NF>1{print $2}' 
fails to produce the same results when run as an event as when being run from the command line.

Thanks for any pointers.

Baobab
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7854
Joined: Mon Oct 01, 2007 10:51 pm

Re: Help with script

Post by admin »

May be environment settings (PATH, etc) might be different when called from within the Meteobridge logger process?
Punching out the environment settings on the scripts start and comparing this might give you a hint.
Post Reply