Page 1 of 1
dzVents os.execute not executing command [Solved]
Posted: Thursday 22 November 2018 10:07
by MikeF
Hi,
I'm running Domoticz (v4.9700) on a RPi, and I'm trying to control powered speakers on a separate RPi using an mpc playlist.
It works if I run the following at the command line:
Code: Select all
sshpass -p <password> ssh pi@<second RPi url> mpc play 1
I've created a selector switch and the following dzVents script:
Code: Select all
--
-- This script plays a streaming radio URL when the device is changed
-- It passes an mpc command to another RPi using sshpass and ssh
--
return {
on = {
devices = { 'Kitchen radio' }
},
execute = function(dz)
local level = dz.devices("Kitchen radio").rawData[1]
level = level / 10
local base = "sshpass -p <password> ssh pi@<second RPi url> mpc play "
if level >= 1 and level <= 7 then
cmd = base .. level
print (cmd)
os.execute(cmd)
end
end
}
However, this appears to do nothing! (I can run the command displayed in the log at the command line OK.)
Re: dzVents os.execute not executing command
Posted: Thursday 22 November 2018 19:32
by waaren
MikeF wrote: Thursday 22 November 2018 10:07
Hi,
I'm running Domoticz (v4.9700) on a RPi, and I'm trying to control powered speakers on a separate RPi using an mpc playlist.
It works if I run the following at the command line:
Code: Select all
sshpass -p <password> ssh pi@<second RPi url> mpc play 1
Can you try with this. It should display what is happening and the returnCode of you command.
Code: Select all
--
-- This script plays a streaming radio URL when the device is changed
-- It passes an mpc command to another RPi using sshpass and ssh
--
return {
on = { devices = { 'Kitchen radio' }},
logging = { level = domoticz.LOG_DEBUG,
marker = "sshPass" },
execute = function(dz, item, info )
_G.logMarker = info.scriptName -- sets the logmarker for dz.log
local function logWrite(str,level)
dz.log(str,level or dz.LOG_DEBUG)
end
local function osExecute(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
logWrite(commandOutput)
logWrite(returnTable[3])
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
local level = dz.devices("Kitchen radio").rawData[1]
level = level / 10
local base = "sshpass -p <password> ssh pi@<second RPi url> mpc play "
if level >= 1 and level <= 7 then
cmd = base .. level
osExecute(cmd)
end
end
}
Re: dzVents os.execute not executing command
Posted: Thursday 22 November 2018 20:03
by MikeF
Thanks, waaren.
This is what I get:
Code: Select all
2018-11-22 18:54:29.098 Status: User: Admin initiated a switch command (276/Kitchen radio/Set Level)
2018-11-22 18:54:29.609 Status: dzVents: Info: sshPass: ------ Start external script: kitchen_radio2.lua: Device: "Kitchen radio (Dummy)", Index: 276
2018-11-22 18:54:29.890 Status: dzVents: Debug: kitchen_radio2:
2018-11-22 18:54:29.890 Status: dzVents: Debug: kitchen_radio2: 6
2018-11-22 18:54:29.890 Status: dzVents: Info: kitchen_radio2: ------ Finished kitchen_radio2.lua
Re: dzVents os.execute not executing command
Posted: Thursday 22 November 2018 20:56
by waaren
MikeF wrote: Thursday 22 November 2018 20:03
Thanks, waaren.
This is what I get:
Code: Select all
2018-11-22 18:54:29.098 Status: User: Admin initiated a switch command (276/Kitchen radio/Set Level)
2018-11-22 18:54:29.609 Status: dzVents: Info: sshPass: ------ Start external script: kitchen_radio2.lua: Device: "Kitchen radio (Dummy)", Index: 276
2018-11-22 18:54:29.890 Status: dzVents: Debug: kitchen_radio2:
2018-11-22 18:54:29.890 Status: dzVents: Debug: kitchen_radio2: 6
2018-11-22 18:54:29.890 Status: dzVents: Info: kitchen_radio2: ------ Finished kitchen_radio2.lua
Could it be the same as
this or related to
this Both pointing to something with Host public key is unknown
Re: dzVents os.execute not executing command [Solved]
Posted: Friday 23 November 2018 0:19
by MikeF
Thanks for these pointers.
The first doesn't work, even after adding the ssh fingerprint of the remote RPi through this command:
Code: Select all
ssh-keyscan -H 192.168.0.9 >> ~/.ssh/known_hosts
However, the second one does!

- by ignoring the check of the host public key, as follows:
I still don't understand why the original sshpass command works at the command line, but not in dzVents (or a python or bash script, for that matter).
Thanks for your help!
