Help with script
Posted: Wed Nov 04, 2020 9:10 am
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:
Here is another, easier to understand version of the same script.
As the one shown above it, it works as intended if executed from the command line as
but fails to work if run as an event. Some additional troubleshooting indicates that
fails to produce the same results when run as an event as when being run from the command line.
Thanks for any pointers.
Baobab
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
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
Code: Select all
nc 127.0.0.1 5556 2>&1 | awk -F '[[:blank:]]+wind0[[:blank:]]+' 'NF>1{print $2}'
Thanks for any pointers.
Baobab