Script execution
Closed this issue · 2 comments
Hi, I have a strange problem.
Raspberry Pi running Heyu and HA-bridge. All lights works just fine, both from web and via Alexa.
I have 1 entry I use to turn on/off a PC.
The ON is calling wakeonlan, works just fine.
To turn it off I created a ssh key on the server running HA-Bridge so to be able to execute a sudo poweroff toward the PC to turn off.
Did put in a script on the server running HA-bridge. If I go on the console of the server and execute the script, the remote PC turn off. All works fine.
However if I call the script from HA-bridge the script apparently is called but nothing happens.
Same permission used for the script top turn it on, no errors I can see on the HA-Bridge.
Did try to call the script with absolute path (/home/pi/./script_name - the same way also to turn it on and it works), using exec, forcing sudo also on the call ... I simply don't get, why only the OFF is not working ?
Any suggestions about that ?
Some strange parameter to be set up in the HA-Bridge for this script ?
Thanks
have you tried setting the execute-bit on the script? (sudo chmod +x scriptname)
I'm calling a lot of bash-scripts from my HA installation, no special HA-Bridge-Setup necessary
Re-reading all the issues gave me the solution.
As stated some times, the main key is to remember that HA-Bridge operates as root.
The failed script was in /home/pi and it used ssh. In order to access the remote machine to be turned off I did set up a pair of keys (to avoid to have the password asked) and thus these keys were stored in the /home/pi/.ssh
When calling the script via console of course it worked because ssh was accessing the created keys.
But when the script was accessed by HA-Bridge, the created keys were not used because starting from root, not /home/pi.
The solution was simple. I just did add the path for the created keys when calling ssh : -i /home/pi/.ssh/id_rsa
Now everything is working fine.
I'm closing the issue.
Hope my experience can be useful to somebody else :)
Cheers
STeve