Execute Command not woking from rule

I can run a script that does a copy from the command line but not openhab.
(when sudo is in the script); if sudo is not in the script, i get permission denied.

Rule text has: executeCommandLine(“bash /etc/openhab2/MoveMailBoxSnaps2.sh”)

That script does this; its a file copy to a mounted share
I’ve tried it with sudo as well(this pic has sudo removed)

Either way i can’t get it to run.
I’ve set the S bits on user and group of the script.
I’ve tried setting the owner to root or openhab nothing works

any ideas?

I’ve also tried adding this to sudoers:

Doesn’t work either.

Try to add this to sudoers:

openhab ALL=(ALL) NOPASSWD: /bin/bash

Its likely the space. If you look at the docs they talk about using “@@” between a binary and its arguments. While you prob don’t think of it like this the “/etc/openhab2/MoveMailBoxSnaps2.sh” part is a argument for the binary “bash”.

If your script has “#!/bin/sh” or equiv at the top and is executable, I’d just remove the “bash” part:


Otherwise you might want to try:


Thanks for the replies tommy and maurits; none of those worked.
I tried adding that line to sudoers and retried the rule; nothing
I tried both ways with the @@ and removing bash, neither worked.
Openhab log says it executes; but it never copies the files(if i run it manually with sudo /etc/openhab2/…sh works fine.

I assume you installed the the Exec binding in the Paper UI.

What if you change the file permissions to ‘x’ instead of ‘s’?

Copy/paste log please.

Ok, so not sure what finally changed.

Do you have to restart openhab to get the sudoers changes to take effect?

Either way, I was doing many combinations of all the suggestions.
Finally, i changed the rule execution to:

executeCommandLine(“sudo /etc/openhab2/MoveMailBoxSnaps2.sh”)

And it worked.

I believe, the combo of removing bash, adding sudo and changing the sudoers as Mauritis suggested(along with maybe a restart of openhab??) got it working

Thanks for the guidance :slight_smile:

1 Like