Error executing script command returned: 256 Topic is solved
Moderator: leecollings
-
JanvdW
- Posts: 118
- Joined: Saturday 21 December 2019 8:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Error executing script command returned: 256
In that case I don't understand why your script is executed in the background, because there's no ampersand in the script?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Error executing script command returned: 256
Because the script does not use the Lua functions os.execute or io.popen but a separate (and async) thread coded in the domoticz program called by the dzVents function dz.executeShellCommand()JanvdW wrote: Friday 05 February 2021 9:54 In that case I don't understand why your script is executed in the background, because there's no ampersand in the script?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
JanvdW
- Posts: 118
- Joined: Saturday 21 December 2019 8:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Error executing script command returned: 256
Thanks; the script works fine. I'll have a look at my other Blockly's to optimize the system
-
JanvdW
- Posts: 118
- Joined: Saturday 21 December 2019 8:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Error executing script command returned: 256
As discussed I am changing my scripts to async versions, but I am struggling with one of my scripts. It's a script that checks presence of family members based on ip connection of their mobiles phone:I added an ampersand to the os.execute command as follows:
. It seems to work (no errors), but results always in positive values, even when devices are not connected. Is something wrong with the syntax?
Code: Select all
return { on = { timer = { "every 5 minutes" } },
logging = { level = domoticz.LOG_INFO, marker = "Ping smartphones" },
data = { timeoutcount = { initial = {} } },
execute = function(dz, device)
local devices_ping = { ['Smartphone 1'] = 'xx.xx.xx.xx',
['Smartphone 2'] = 'xx.xx.xx.xx',
['Smartphone 3'] = 'xx.xx.xx.xx',
['Smartphone 4'] = 'xx.xx.xx.xx',
['Smartphone 5'] = 'xx.xx.xx.xx'}
local timeout = 3 -- # timeouts, before a switch off will be executed
local timeoutcount = dz.data.timeoutcount -- short reference
for deviceName, ipaddr in pairs(devices_ping) do
ping_success=""
ping_success=os.execute('ping -c1 -w1 ' .. ipaddr)
if timeoutcount[deviceName] == nil then
timeoutcount[deviceName] = 0
end
if ping_success then
if timeoutcount[deviceName] == 0 then
print("ping "..deviceName.." success ")
else
if timeoutcount[deviceName] >= timeout then -- log wordt alleen weggeschreven als device offline is geweest
print("ping "..deviceName.." success, device is back.")
end
timeoutcount[deviceName] = 0 -- reset the counter
end
if dz.devices(deviceName).state == 'Off' then
dz.devices(deviceName).switchOn()
end
elseif timeoutcount[deviceName] < timeout then
timeoutcount[deviceName] = timeoutcount[deviceName] + 1
print("ping ".. deviceName .." ".. timeoutcount[deviceName] .." times failed.")
end
if timeoutcount[deviceName] >= timeout then
--print ("ping ".. deviceName .." has " ..timeoutcount[deviceName].. " timeouts, this exceeds the timeout number setting.")
if dz.devices(deviceName).state == 'On' then
dz.devices(deviceName).switchOff()
end
end
end
end
}Code: Select all
ping_success=os.execute('"ping -c1 -w1 " .. ipaddr &')- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Error executing script command returned: 256
Not directly with the syntax but the os.execute does not return the resultcode of the ping command but it returns the result of the &, meaning that it returns the result of sending the command to the background which always succeeds.JanvdW wrote: Monday 22 February 2021 22:48 As discussed I am changing my scripts to async versions, but I am struggling with one of my scripts. It's a script that checks presence of family members based on ip connection of their mobiles phone:
I added an ampersand to the os.execute command as follows:. It seems to work (no errors), but results always in positive values, even when devices are not connected. Is something wrong with the syntax?Code: Select all
ping_success=os.execute('"ping -c1 -w1 " .. ipaddr &')
This behavior was one of the main reasons to develop the executeShellCommand() in dzVents (available in dzVents >= 3.1.0 / build >= 12771) which is true async and returns its result via trigger shellCommandResponses
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
JanvdW
- Posts: 118
- Joined: Saturday 21 December 2019 8:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Error executing script command returned: 256
That explains what happens; thanks for your explanation. I had a look already at executeShellCommand() already, but it was not clear to me how to use it in a loop, where the executeShellCommand() is called for multiple (in my case 5) devices.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Error executing script command returned: 256
In this case I would leave the looping to the ShellCommand. Below small bash script will do it for you and nicely shows the result in a JSON that can be processed further in dzVents when it is returned by the shellCommandResponseJanvdW wrote: Tuesday 23 February 2021 8:23 That explains what happens; thanks for your explanation. I had a look already at executeShellCommand() already, but it was not clear to me how to use it in a loop, where the executeShellCommand() is called for multiple (in my case 5) devices.
bash script
Code: Select all
#! /bin/bash
#
# bash script to loop over all parms and ping them. Parms should be a valid IPv4 or IPv6 address or hostname
#
# call like ./myPing.sh dz 192.168.192.1 192.168.192.199 8.8.8.8 noHost ::1 home.synology.me
# output will look like
#
# {"dz":0,"192.168.192.1":0,"192.168.192.199":1,"8.8.8.8":0,"noHost":2,"::1":0,"home.synology.me":0,}
#
myJSON='{'
#
# Loop over all parms
#
for ((i=1; i<=$#; i++))
do
ping -q -c1 -w1 ${!i} > /dev/null 2>&1
myJSON=$myJSON\"${!i}\":$?, # add ip + result to the JSON
done
echo ${myJSON::-1}"}" # remove last , and add }
dzVents part
Code: Select all
local scriptVar = 'shell pinger'
return
{
on =
{
timer =
{
'every minute',
},
shellCommandResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
if item.isTimer then
local IPTable =
{
"dz",
"192.168.192.1",
"192.168.192.199",
"8.8.8.8",
"noHost",
"::1",
"home.synology.me",
}
dz.executeShellCommand(
{
command = '/home/pi/domoticz/scripts/myPinger.sh ' .. table.concat(IPTable,' '),
callback = scriptVar,
timeout = #IPTable -- same number of seconds as there are entries in IPTable
})
elseif item.isShellCommandResponse and item.json then
rt = item.json
for host, rc in pairs(rt) do
dz.log('Ping result of "' .. host .. '" : ' .. rc, dz.LOG_DEBUG)
end
else
dz.log('There was a problem handling the command', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
JanvdW
- Posts: 118
- Joined: Saturday 21 December 2019 8:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Error executing script command returned: 256
That's a good idea to solve this.
I implemented this but have some errors:
I implemented this but have some errors:
- strange enough I get the following error message:
Code: Select all
Error: dzVents script command running longer than specified timeout(5 seconds), cancelling...
- At other moments I get log entries like
Code: Select all
2021-02-23 14:20:05.736 Error: dzVents: Error: (3.1.5) shell pinger: Error parsing json to LUA table: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:808: trailing garbage at byte 231 of: {"xx.xx.xx.xx":0,"xx.xx.xx.xx":0,"xx.xx.xx.xx":0,"xx.xx.xx.xx":1,"xx.xx.xx.xx":1} 2021-02-23 14:20:05.736 {"xx.xx.xx.xx":0,"xx.xx.xx.xx":0,"xx.xx.xx.xx":0,"xx.xx.xx.xx":1,"xx.xx.xx.xx":1,"xx.xx.xx.xx":0,"xx.xx.xx.xx":0,"xx.xx.xx.xx":0,"xx.xx.xx.xx":1,"xx.xx.xx.xx":1,} 2021-02-23 14:20:05.736 Error: dzVents: Error: (3.1.5) shell pinger: There was a problem handling the command 2021-02-23 14:20:12.657 Error: dzVents script command running longer than specified timeout(5 seconds), cancelling..
- erem
- Posts: 230
- Joined: Tuesday 27 March 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Amsterdam/netherlands
- Contact:
Re: Error executing script command returned: 256
@JanvdW
check your line endings in the script.
I'll bet the trailing garbage is cr-lf from a cut-paste from a windows editor.
check your line endings in the script.
I'll bet the trailing garbage is cr-lf from a cut-paste from a windows editor.
Regards,
Rob
Rob
-
JanvdW
- Posts: 118
- Joined: Saturday 21 December 2019 8:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Error executing script command returned: 256
Found the issue; it appears that the bash script was corrupted.
I have one question left. Based on the timer the script starts at 20:45:00.726 and finished at 20:45:00.826. Then the ShellCommandResponse starts the script at 20:45:05.035 and finished at 20:45:05.062
I don't understand why I get an error message that timeout of 12 seconds is exceeded:. A message that I get over and over again.
I have one question left. Based on the timer the script starts at 20:45:00.726 and finished at 20:45:00.826. Then the ShellCommandResponse starts the script at 20:45:05.035 and finished at 20:45:05.062
I don't understand why I get an error message that timeout of 12 seconds is exceeded:
Code: Select all
Error: dzVents script command running longer than specified timeout(12 seconds), cancelling...- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Error executing script command returned: 256
What is your build?JanvdW wrote: Tuesday 23 February 2021 16:47 I don't understand why I get an error message that timeout of 12 seconds is exceeded:. A message that I get over and over again.Code: Select all
Error: dzVents script command running longer than specified timeout(12 seconds), cancelling...
The errormessage could be the bug that was introduced in build 12970 and fixed in build 12974
If you are on build >= 12974 and still see the message then try and change line
Code: Select all
timeout = #IPTable -- same number of seconds as there are entries in IPTable
Code: Select all
timeout = ( #IPTable + 10 ) -- same number of seconds as there are entries in IPTable + 10 Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
JanvdW
- Posts: 118
- Joined: Saturday 21 December 2019 8:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Error executing script command returned: 256
Great; thanks. The system was on build 12972. After upgrade (to 12983) the error message is gone.