Escaping arguments for Exec Binding

Hi,

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(GenericItemChannelLinkProvider.java:82) ~[?:?]
        at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.processBindingConfiguration(GenericItemChannelLinkProvider.java:72) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:369) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:338) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:210) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:404) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:311) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:149) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:247) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:310) ~[?:?]
        at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3(WatchQueueReader.java:323) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_302]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_302]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_302]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_302]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_302]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_302]
        at java.lang.Thread.run(Thread.java:748) [?: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@192.168.0.41 'source /home/nao/.bash_profile; python albehaviormanager.py --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@192.168.0.41 \'source/home/nao/.bash_profile; python albehaviormanager.py --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@192.168.0.41 'source /home/nao/.bash_profile; python albehaviormanager.py --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.