Page 1 of 1

SOLVED bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 17:50
by antipiot
Hello mates :-)

I'm facing a problem to use a script in an event:

My script works when the line is issued in terminal ssh but now when run from a switch or event:
Domoticz is in latest stable. Script has been chmoded.

My script is used to:
SSH from domoticz PI into my PI network player then shut it down:

This

Code: Select all

#!/bin/bash
sshpass -p "password" ssh [email protected] sudo bash /var/local/www/commandw/restart.sh "reboot" > /dev/null 2>&1 &
Works when run from ssh as:

Code: Select all

bash /home/pi/domoticz/scripts/audio_shutdown.sh
But i get an error when used in switch or event:
2018-05-16 17:48:20.071 User: admin initiated a switch command (232/test/Off)
2018-05-16 17:48:20.203 (Virtual Switch) Light/Switch (test)
2018-05-16 17:48:20.289 Executing script: /home/pi/domoticz/scripts/audio_shutdown.sh
2018-05-16 17:48:20.302 Error: Error executing script command (/home/pi/domoticz/scripts/audio_shutdown.sh). returned: 32512

Does anybody of you have any idea of what's happening?

Thanks for your help :-)

EDIT 1: 1 step forward:

I created a new file and copy / pasted my script into it then saved as audio_shutdown.sh and i now get this when executed:

Code: Select all

 2018-05-16 18:03:14.219 User: admin initiated a switch command (232/test/On)
2018-05-16 18:03:14.352 (Virtual Switch) Light/Switch (test)
2018-05-16 18:03:14.439 Executing script: /home/pi/domoticz/scripts/audio_shutdown.sh
2018-05-16 18:03:14.452 Error: Error executing script command (/home/pi/domoticz/scripts/audio_shutdown.sh).[b] returned: 512 [/b]
EDIT 2: 2nd step:

I was able to get another step forward:
Had to save my script in a notepad and importing it in domoticz (notepad ++ didn't worked)
Now, no more error but script still doesen't work

EDIT 3: Last step : SOLVED: Last post:

Solved! YAY!!!!

Had to to with keys like @heggink pointed me:

Working command ignore keys as suggested in:
https://www.cyberciti.biz/faq/nonintera ... -provider/

Code: Select all

#!/bin/bash
sshpass -p "password" ssh -o StrictHostKeyChecking=no [email protected] sudo bash /var/local/www/commandw/restart.sh "reboot"

Thanks for your help and suggestions! :P
Top

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 19:17
by jvdz
Have you checked the execute bit for the file?

Jos

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 19:25
by heggink
I had a similar situation where I run scripts on another system from ssh. I didn't want to use password stuff so generated keys so I coukd just ssh with no questions asked (not very secure but I rely on nobody being able to break into my network). It worked from the regular user but not from the domoticz daemon since that process has different privileges. Generating ssh keys for root fixes it (even more insecure but hey...) :-).

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 20:03
by antipiot
jvdz wrote: Wednesday 16 May 2018 19:17 Have you checked the execute bit for the file?

Jos
Hello Jos, How are you? Thanks for your help:

I was able to get another step forward:
Had to save my script in a notepad and importing it in domoticz (notepad ++ didn't worked)

No more error (YAY) now but script still doesen't work from an event or switch :?:

Don't know how to check this bit:
gonna check this now.

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 20:09
by antipiot
heggink wrote: Wednesday 16 May 2018 19:25 I had a similar situation where I run scripts on another system from ssh. I didn't want to use password stuff so generated keys so I coukd just ssh with no questions asked (not very secure but I rely on nobody being able to break into my network). It worked from the regular user but not from the domoticz daemon since that process has different privileges. Generating ssh keys for root fixes it (even more insecure but hey...) :-).
May you explain me how or point me the right thing to try? Thanks for your hint :-)

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 20:16
by jvdz
Just SSH into your PI, cd to the correct directory and do: ls -l
Show the output line for the script.

Jos

ps: Doing well ;)

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 20:19
by antipiot
jvdz wrote: Wednesday 16 May 2018 20:16 Just SSH into your PI, cd to the correct directory and do: ls -l
Show the output line for the script.

Jos

ps: Doing well ;)
Here you go, thanks for your time :-)
Don't think it's right related: i've read somwhere that this problem may be caused by domoticz being executed as root or something like that:

Code: Select all

-rwxrwxrwx 1 pi pi  120 May 16 19:58 audio_shutdown.sh
-rwxrwxrwx 1 pi pi  124 May 16 17:55 audio_shutdown.sh.bak
-rw-r--r-- 1 pi pi 2834 Nov 14  2016 buienradar_rain_example.pl
-rw-r--r-- 1 pi pi  234 Nov 14  2016 _domoticz_main
-rw-r--r-- 1 pi pi  185 Nov 14  2016 _domoticz_main.bat
-rwxr-xr-x 1 pi pi 1126 Nov 14  2016 download_update.sh
drwxr-xr-x 8 pi pi 4096 Jul 16  2017 dzVents
drwxr-xr-x 2 pi pi 4096 Nov 14  2016 logrotate
drwxr-xr-x 2 pi pi 4096 Nov 14  2016 lua
drwxr-xr-x 2 pi pi 4096 Nov 14  2016 lua_parsers
drwxr-xr-x 2 pi pi 4096 Jun  2  2017 python
-rw-r--r-- 1 pi pi  246 Nov 14  2016 readme.txt
-rwxr-xr-x 1 pi pi  125 Nov 14  2016 restart_domoticz
drwxr-xr-x 2 pi pi 4096 Jul 27  2017 templates
-rwxr-xr-x 1 pi pi  669 Nov 14  2016 update_domoticz

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 20:25
by antipiot
antipiot wrote: Wednesday 16 May 2018 20:19
jvdz wrote: Wednesday 16 May 2018 20:16 Just SSH into your PI, cd to the correct directory and do: ls -l
Show the output line for the script.

Jos

ps: Doing well ;)
Here you go, thanks for your time :-)
Don't think it's right related: i've read somwhere that this problem may be caused by domoticz being executed as root or something like that:

Code: Select all

-rwxrwxrwx 1 pi pi  120 May 16 19:58 audio_shutdown.sh
-rwxrwxrwx 1 pi pi  124 May 16 17:55 audio_shutdown.sh.bak


Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 20:31
by jvdz
That look all good. What about adding sudo at the beginning of the commandline in the bash file to see whether that fixes it?

Jos

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Wednesday 16 May 2018 20:37
by antipiot
jvdz wrote: Wednesday 16 May 2018 20:31 That look all good. What about adding sudo at the beginning of the commandline in the bash file to see whether that fixes it?

Jos
Still no luck:

Code: Select all

#!/bin/bash
sudo sshpass -p "password" ssh [email protected] bash /var/local/www/commandw/restart.sh "reboot" > /dev/null 2>&1 &

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Thursday 17 May 2018 13:22
by heggink
here is a link (I think I used it myself): https://www.tecmint.com/ssh-passwordles ... asy-steps/ or another one http://www.linuxproblem.org/art_9.html
Be aware that you need to do this for every user that uses ssh so if domoticz runs as a daemon, 1) generate the keys as root (sudo -s) and then test the keys as root as well!
Works like a charm for me between multiple systems for me BUT BE AWARE THAT IT EXPOSES YOUR SYSTEM so ensure your network cannot be hacked!!!

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Thursday 17 May 2018 15:11
by antipiot
heggink wrote: Thursday 17 May 2018 13:22 here is a link (I think I used it myself): https://www.tecmint.com/ssh-passwordles ... asy-steps/ or another one http://www.linuxproblem.org/art_9.html
Be aware that you need to do this for every user that uses ssh so if domoticz runs as a daemon, 1) generate the keys as root (sudo -s) and then test the keys as root as well!
Works like a charm for me between multiple systems for me BUT BE AWARE THAT IT EXPOSES YOUR SYSTEM so ensure your network cannot be hacked!!!
Thanks for this:
I think i have another issue since i dont use "paswordless" login but sshpass.
i dont formely have a passwordless login:
https://www.cyberciti.biz/faq/nonintera ... -provider/

Gonna try anyway :-) maybe it's less pain to use this aswell :D

Re: bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Thursday 17 May 2018 18:11
by antipiot
Solved! YAY!!!!

Had to to with keys like @heggink pointed me:

Working command ignore keys as suggested in:
https://www.cyberciti.biz/faq/nonintera ... -provider/

This can now be used on a raspberry to shutdown moode audio player with a script using sshpass:

Code: Select all

#!/bin/bash
sshpass -p "password" ssh -o StrictHostKeyChecking=no [email protected] sudo bash /var/local/www/commandw/restart.sh "reboot"
Thanks for your help and suggestions! :P

Re: SOLVED bash - Error 512 - Script works with ssh but not in event or Switch

Posted: Thursday 17 May 2018 20:03
by heggink
Great! another happy domoticz user :-)