CommandLine execution in a Rule - sudo "openhab-cli backup" no go

Good afternoon.

Running OpenHABian (app 3.1) and I wanted to create a Rule that whenever I manually told it to run, it would kick off the “openhab-cli backup” command.

Poking around in the various threads, I found that I should be able to create this rule:

triggers: [ ]
conditions: [ ]

  • inputs: { }
    id: “1”
    type: application/javascript
    script: |
    executeCommandLine(“sudo openhab-cli backup”)
    type: script.ScriptAction

I’ve also added the following line to the SUDOERS file:

openhab ALL=(ALL) NOPASSWD: /usr/bin/openhab-cli

I’ve even played with the SUDOERS file being “openhabian” instead, but neither seem to work. I click play on the rule, it runs for a second, but no new/additional backup files are made.

Clearly I’m missing something, but in theory I’ve given that user rights to run the command w/o password prompting. Does anyone see anything glaringly wrong with this as to why it wouldn’t work?


executeCommandLine can be called with different options see:

Make use of the one that passes back the output into a variable which then can be printed into a logfile.
The message that you receive then should help to analyze the problem:
var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/my/");