Lua script executing sh script... not working! Topic is solved

Moderator: leecollings

echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Lua script executing sh script... not working!

Post by echeberri77 »

Hello guys,
I searched this forum for a couple of days before posting but I did't find any way to solve my problem.
I have this lua script named script_device_lights.lua, located under /xavier/domoticz/scripts/lua/

Code: Select all

commandArray = {} 

if (devicechanged['Luci corridoio'] == 'On') then
os.execute ("/home/xavier/domoticz/scripts/luci_corridoio.sh")
end 
return commandArray
This is the content of the bash script luci_corridoio.sh:

Code: Select all

#!/bin/bash
izsynth -e naturalreaders -v Federica -t "Luci del corridoio accese"
I have a dummy light switch connected to my sonoff: when I trigger the switch 'Luci corridoio' I have my lights ON and the lua script execute luci_corridoio.sh that should simply play a vocal message saying my lights are on.

This is the domoticz log:
2018-03-22 19:02:40.214 (SonOff_corridoio) Lighting 1 (Luci corridoio)
2018-03-22 19:02:40.423 Executing script: /home/xavier/domoticz/scripts/luci_corridoio.sh
2018-03-22 19:02:41.269 MQTT: Topic: domoticz/in, Message: {"idx":13,"nvalue":0,"svalue":""}
2018-03-22 19:02:41.274 LUA: Time set to Night

My lua script is chmod +x and 755
My sh script is chmod +x and 755

If I launch my sh script in a terminal Windows using both root and not-root users it is working and I am able to hear the message... THE PROBLEM IS THAT WHEN THE SH SCRIPT IS EXECUTED BY DOMOTICZ I SIMPLY CAN'T HEAR ANYTHING (sorry for the capital letters.....)

Could you please help me to understand my error because it is driving me totally crazy!

Thanks!!!

Echeberri
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Lua script executing sh script... not working!

Post by freijn »

Hi Echeberri

please try the following where i have the second one successfully running here.

os.execute ('/home/xavier/domoticz/scripts/luci_corridoio.sh')
or better
os.execute ('/home/xavier/domoticz/scripts/luci_corridoio.sh &')
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

freijn wrote:Hi Echeberri

please try the following where i have the second one successfully running here.

os.execute ('/home/xavier/domoticz/scripts/luci_corridoio.sh')
or better
os.execute ('/home/xavier/domoticz/scripts/luci_corridoio.sh &')
Hi,
I tried to modify my Lua script as you suggested but It is still not working.
Domoticz executes the sh batch but I can't hear any sound (if I launch the same sh batch in a terminal Window It works perfectly...).
Any hint? :-(

Inviato dal mio MHA-L29 utilizzando Tapatalk

freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Lua script executing sh script... not working!

Post by freijn »

The only thing I can think of is that if Domoticz exe the script you are a different user.

Assuming the domoticz user does not have access to the sound device or the file which need to be played.

what happens in the script ?
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

freijn wrote:The only thing I can think of is that if Domoticz exe the script you are a different user.

Assuming the domoticz user does not have access to the sound device or the file which need to be played.

what happens in the script ?
How to see which user is used by domotics? How to assign to this user more priviledges?

Inviato dal mio MHA-L29 utilizzando Tapatalk

echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

echeberri77 wrote:
freijn wrote:The only thing I can think of is that if Domoticz exe the script you are a different user.

Assuming the domoticz user does not have access to the sound device or the file which need to be played.

what happens in the script ?
How to see which user is used by domotics? How to assign to this user more priviledges?

Inviato dal mio MHA-L29 utilizzando Tapatalk
I granted chmod 777 to izsynth directory and executable but nothing changed! I Simply can't hear sound... I was wondering how to give access to everyone to sound card... Hmmm.... But is It necessary?

Inviato dal mio MHA-L29 utilizzando Tapatalk

jannl
Posts: 686
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Lua script executing sh script... not working!

Post by jannl »

Not only access rights, also path settings and environment vars (if used) should be checked.

Besides, as far as I can see I do not see an error.....
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

echeberri77 wrote:
echeberri77 wrote:
freijn wrote:The only thing I can think of is that if Domoticz exe the script you are a different user.

Assuming the domoticz user does not have access to the sound device or the file which need to be played.

what happens in the script ?
How to see which user is used by domotics? How to assign to this user more priviledges?

Inviato dal mio MHA-L29 utilizzando Tapatalk
I granted chmod 777 to izsynth directory and executable but nothing changed! I Simply can't hear sound... I was wondering how to give access to everyone to sound card... Hmmm.... But is It necessary?

Inviato dal mio MHA-L29 utilizzando Tapatalk
I also added all users to the group "sound" but sh is still mute if played by domoticz... Hmmmm....

Inviato dal mio MHA-L29 utilizzando Tapatalk

echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

jannl wrote:Not only access rights, also path settings and environment vars (if used) should be checked.

Besides, as far as I can see I do not see an error.....
Path settings are correct because domoticz executes the sh script... (So It means sh file is found). Domoticz script directory is chmod 777 and There aren't any environment vars used...

Inviato dal mio MHA-L29 utilizzando Tapatalk

jannl
Posts: 686
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Lua script executing sh script... not working!

Post by jannl »

I mean the path settings in the script. Does the script find everything it needs?
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

jannl wrote:I mean the path settings in the script. Does the script find everything it needs?
Read above: i think the script is Pretty simple. I press a dummy switch that switchs a lamp on. When this device changes to ON position It triggers a sh script. I can read from the log that domoticz correctly executes the sh script but no sound Can be heard... If i launch the same sh script from a terminal windows using a non root user I am able to hear the sound...

Inviato dal mio MHA-L29 utilizzando Tapatalk

jannl
Posts: 686
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Lua script executing sh script... not working!

Post by jannl »

Hm. Read what I wrote. Off course Domoticz executes the script. You entered the path.

The script itself propably does not find the binary you try to call.

Not sure what you know about how linux works, but when a shell is forked (what happens when executing the script like this), most likely that shell does not have a lot of settings, hence my remarks.
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

jannl wrote:Hm. Read what I wrote. Off course Domoticz executes the script. You entered the path.

The script itself propably does not find the binary you try to call.

Not sure what you know about how linux works, but when a shell is forked (what happens when executing the script like this), most likely that shell does not have a lot of settings, hence my remarks.
By binary you mean the izsynth executable? It is on the system path and i can call It from any directory and It is rwx for all users.

Inviato dal mio MHA-L29 utilizzando Tapatalk

jannl
Posts: 686
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Lua script executing sh script... not working!

Post by jannl »

The script most likely has no path (or did you check). Try using the complete path to the binary.
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

echeberri77 wrote:
jannl wrote:Hm. Read what I wrote. Off course Domoticz executes the script. You entered the path.

The script itself propably does not find the binary you try to call.

Not sure what you know about how linux works, but when a shell is forked (what happens when executing the script like this), most likely that shell does not have a lot of settings, hence my remarks.
By binary you mean the izsynth executable? It is on the system path and i can call It from any directory and It is rwx for all users.

Inviato dal mio MHA-L29 utilizzando Tapatalk
Is There a way to have a more verbose domoticz log? Maybe It could help...

Inviato dal mio MHA-L29 utilizzando Tapatalk

jannl
Posts: 686
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Lua script executing sh script... not working!

Post by jannl »

The error ia not in Domoticz. The script has an error (i think). If Domoticz had an error it would be in the logging. Just try adding the complete path to the binary in the script.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Lua script executing sh script... not working!

Post by freijn »

os.execute ('/home/xavier/domoticz/scripts/luci_corridoio.sh /home/log/myscript.log')

try the above. and see /home/log/myscript.log
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

jannl wrote:The script most likely has no path (or did you check). Try using the complete path to the binary.
Please be more specific: Lua script or sh script?
Lua script is inside domoticz/script. Inside Lua script I read:
... Os.execute ('/domoticz/script/luci_corridoio.sh')
Also this path is correct because domoticz log tells me that domoticz started the sh script.
Let's go inside the sh script:
I Simply execute ezsynth with some arguments.
I can't really find any path issues...

Inviato dal mio MHA-L29 utilizzando Tapatalk

jannl
Posts: 686
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Lua script executing sh script... not working!

Post by jannl »

The path ezsynth inside the script. The script itself is executed as shown in the Domoticz log
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Re: Lua script executing sh script... not working!

Post by echeberri77 »

jannl wrote:The path ezsynth inside the script. The script itself is executed as shown in the Domoticz log
Ok, I'll adding complete path. I'll let you know. Thanks!

Inviato dal mio MHA-L29 utilizzando Tapatalk

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest