As documented, you must supply a Duration as the first argument to executeCommandLine in order to cause it to wait for the command to finish and capture the command’s output.
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
That message comes up the first time a user runs a sudo command and requires you to press “y” to acknowledge the message. Probably the easiest thing to do is open a terminal and run
sudo -u openhab /bin/bash
to get a shell as user openhab. The run
sudo ls
That message will appear and present you with a y/n prompt. From that point the message will not appear again and your executeCommandLine should work.
I’ve done just that. I wanted to make sure it solved your problem before making the edit.
If I recall correctly, when Debian Buster came out, it was unclear which commands would work in both Buster and Jessie. I had written this note:
EDIT: The code below has been updated to delete /sbin/reboot and add /sbin/shutdown and /sbin/systemctl, which should enable this tutorial to work with both the Debian Jessie and the newest Debian Buster operating systems. However, I have not personally tested/confirmed that it works on Debian Buster. See the discussion comments for more information, and please provide feedback if it does/doesn’t work for you.
However, I didn’t update the rule to match. Now that we know sbin/reboot works in Buster, it’s easiest to just add that back.
The problem was that the zram implementation in openHABian didn’t work correctly when one used reboot as opposed to shutdown -r. That has since been resolved so both commands work correctly with zram now.
Well I wouldn’t call it misconfigured. It’s the default, and for good reasons so.
Under normal operating conditions, the openhab user should not need to have access to system level privileges.
The OP shouldn’t be booting his server anyway.
Hello there! I’m moving to OH3 and at this point i’m copying rules from my OH2 environment. I have 2 rules (working on OH2) that launch a reboot of service/shoutdown the servoce of OH2,but won’t work on OH3.
My command is: sudo systemctl restart openhab.service
I’ve followed above steps to update sudoers etc,but won’t work.
Btw, raspi reboot/shutdown are working correctly. I run rule on openhabian image and the command has been executed with executeCommandLine.
Last,if i run from ssh the command sudo systemctl restart openhwb.service, it shows me an info and then restart the service correctly without any other input.
Any help from any guru will be appreciated a lot.
Show your rules to get more help.
You adapted your executeCommandLine syntax from OH2 to the syntax of OH3 ?
In case it does not work get the returned string from executeCommandLine and print it to loginfo to check what the output message / error message is.