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

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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
Last edited by antipiot on Thursday 17 May 2018 18:19, edited 3 times in total.
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post by jvdz »

Have you checked the execute bit for the file?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

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

Post 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...) :-).
Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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.
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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 :-)
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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 ;)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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

User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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 &
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

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

Post 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!!!
Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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
antipiot
Posts: 45
Joined: Wednesday 03 January 2018 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Switzerland
Contact:

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

Post 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
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

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

Post by heggink »

Great! another happy domoticz user :-)
Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest