Page 1 of 1

os.execute: syntax for mqtt command in sh script ?

Posted: Friday 04 October 2019 17:52
by midomot
I have a LED strip with Tasmota, all integrated in domoticz.
Trying to see if I could make a sh script that would run my own sequence of lights (I'd call the script from a switch with & )

In lua, in domoticz Events, I can issue

Code: Select all

os.execute('mosquitto_pub -h 127.0.0.1 -u xxx -P xxx -t cmnd/LEDLightStrip/Power -m on')
and it works

On the command line of the pi (ssh), I can issue

Code: Select all

mosquitto_pub -h 127.0.0.1 -u xxx -P xxx -t cmnd/LEDLightStrip/Power -m on 
and it also works

however, if I try to put the above or variations thereof into a sh script, I get failure
something in the syntax.. I spent a little while on this, and can't figure it out. Probably a combination of " and '...
For ex with code

Code: Select all

#!/bin/bash
os.execute('mosquitto_pub -h "127.0.0.1" -u "xxx" -P "xxx" -t "cmnd/LEDLightStrip/Power" -m "on"')
then I get

Code: Select all

~/domoticz/scripts $ ./zzTestScript.sh
./zzTestScript.sh: line 2: syntax error near unexpected token `'mosquitto_pub -h "127.0.0.1" -u "xxx" -P "xxx" -t "cmnd/LEDLightStrip/Power" -m "on"''
Who can tell me what I'm doing wrong ? thanks !

Re: os.execute: syntax for mqtt command in sh script ?

Posted: Friday 04 October 2019 18:15
by midomot
Seems to work just fine now with just this in the sh file..

Code: Select all

#!/bin/sh
/usr/bin/mosquitto_pub -h 127.0.0.1 -u xxx -P xxx -t cmnd/LEDLightStrip/Power -m on