Escaping arguments for Exec Binding


I use Ubuntu 20.04 and still openHAB 2 and of course the exec binding.

I got following error:

16:45:27.080 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'pepper.items'
16:45:27.084 [ERROR] [del.item.internal.GenericItemProvider] - Binding configuration of type 'channel' of item 'gPepper02_Infoterminal' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: ID segment '[exec' contains invalid characters. Each segment of the ID must match the pattern [A-Za-z0-9_-]*.
        at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.createItemChannelLink( ~[?:?]
        at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.processBindingConfiguration( ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings( ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings( ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel( ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged( ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners( ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel( ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile( ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent( ~[?:?]
        at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3( ~[?:?]
        at java.util.concurrent.Executors$ [?:1.8.0_302]
        at [?:1.8.0_302]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201( [?:1.8.0_302]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ [?:1.8.0_302]
        at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:1.8.0_302]
        at java.util.concurrent.ThreadPoolExecutor$ [?:1.8.0_302]
        at [?:1.8.0_302]

I tried it with \" or \' and @@ for the free spaces. Maybe you can help me:

My exec.whitelist:

/usr/bin/ssh -t -o StrictHostKeyChecking=no nao@ 'source /home/nao/.bash_profile; python --function runBehavior --behavior_name "User/11_infoterminal-ade9a3/behavior_1"'

The pepper.items:

Switch gPepper02_Infoterminal (gPepper02_UserBehaviors) { channel="[exec:command:Pepper02InfoterminalRun:run]" }

And the pepper.things:

Thing exec:command:Pepper02InfoterminalRun [command="/usr/bin/ssh -t -o StrictHostKeyChecking=no nao@ \'source/home/nao/.bash_profile; python --function runBehavior --behavior_name \"User/11_infoterminal-ade9a3/behavior_1\"\'", interval=0, autorun=false]

I hope you can help me. Running sudo -u openhab /usr/bin/ssh -t -o StrictHostKeyChecking=no nao@ 'source /home/nao/.bash_profile; python --function runBehavior --behavior_name "User/11_infoterminal-ade9a3/behavior_1"' works fine by the way.

So that’s where the problem lies.

Pretty clear.

That’s the bit it doesn’t like.
Do any of your other channels have square brackets around them? What makes you think they’re needed here, is there a documentation error?

Sorry my fault. It works with:

Switch gPepper02_Infoterminal (gPepper02_UserBehaviors) { channel="exec:command:Pepper02InfoterminalRun:run" }

I forgot to delete it because I tried:

Switch gPepper02_Infoterminal (gPepper02_UserBehaviors) { channel="[ON: exec:command:Pepper02InfoterminalRun:run], [OFF: exec:command:Pepper02InfoterminalStop:run]" }

I don’t have a solution for ON and OFF yet. What I can do then would be two switches. But that would not necessarily be the optimal solution. I have seen here in the forum somewhere such a solution, but that is obviously wrong.

Don’t know what you need to do. Run scripts with different names?

The Exec binding gives you a string-type input channel, so that you can drop the string into the command using %2$s
Doesn’t help much if you start off with strings ON or OFF and need some other string as the difference.

You could of course have a rule triggered by Switch Item that maps ON/OFF to script name and commands that to Exec String input Item.

By the time you’ve done that, you might as well forget the Exec binding and use executeCommandLine() directly in a rule.