[SOLVED] I cant run simple sh script

i run openhab2 on windows 10
If I run this script through a terminal in linux then it works
this is my script:

#!/bin/bash
curl -d '{"id":"test", "action":"activate"}' -H 'Content-Type: application/json' -X PUT http://192.168.0.111:8888/api/scenes

this is my rule:

rule "test rule"

when

 Item testbutton changed 

then

 executeCommandLine("C:/openHAB2/conf/scripts/ledfx.sh")

end

is the script in windows running if you call it?
I can only run .sh scripts on my windows machine since git is installed…

Thank you for the response
git is not installed on my computer, I will install and try again

I installed git and the script works if I run it manually but through the rule it does not work

What log do you get in OH when you trigger the rule?
BTW i would either create a .bat file and call that instead of a linux shell script.

that the log:

2021-04-29 20:35:42.630 [ERROR] [lipse.smarthome.io.net.exec.ExecUtil] - couldn't execute commandLine 'C:/openHAB2/conf/scripts/ledfx.sh'

java.io.IOException: Cannot run program "C:/openHAB2/conf/scripts/ledfx.sh": CreateProcess error=193, %1 is not a valid Win32 application

       at java.lang.ProcessBuilder.start(ProcessBuilder.java:1128) ~[?:?]

       at java.lang.ProcessBuilder.start(ProcessBuilder.java:1071) ~[?:?]

       at java.lang.Runtime.exec(Runtime.java:592) ~[?:?]

       at java.lang.Runtime.exec(Runtime.java:416) ~[?:?]

       at java.lang.Runtime.exec(Runtime.java:313) ~[?:?]

       at org.eclipse.smarthome.io.net.exec.ExecUtil.executeCommandLine(ExecUtil.java:63) [bundleFile:?]

       at org.eclipse.smarthome.model.script.actions.Exec.executeCommandLine(Exec.java:42) [bundleFile:?]

       at jdk.internal.reflect.GeneratedMethodAccessor663.invoke(Unknown Source) ~[?:?]

       at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

       at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1175) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1150) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1136) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:1081) [bundleFile:?]

       at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:151) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:991) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:954) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:235) [bundleFile:?]

       at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:215) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:458) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:239) [bundleFile:?]

       at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:215) [bundleFile:?]

       at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:201) [bundleFile:?]

       at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:81) [bundleFile:?]

       at org.eclipse.smarthome.model.rule.runtime.internal.engine.RuleEngineImpl.lambda$2(RuleEngineImpl.java:313) [bundleFile:?]

       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]

       at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]

       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]

       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]

       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]

       at java.lang.Thread.run(Thread.java:834) [?:?]

Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application

       at java.lang.ProcessImpl.create(Native Method) ~[?:?]

       at java.lang.ProcessImpl.<init>(ProcessImpl.java:478) ~[?:?]

       at java.lang.ProcessImpl.start(ProcessImpl.java:154) ~[?:?]

       at java.lang.ProcessBuilder.start(ProcessBuilder.java:1107) ~[?:?]

Call curl directly without the script. The logfile tells you the problem. It has problems running the .sh as a process. Search curl here in the forum. There should be examples

I found the solution:
I first had to redirect to git and add @@

executeCommandLine("C:/Program Files/Git/git-bash.exe@@C:/openHAB2/conf/scripts/ledfx.sh")

Ok. Why don’t you call the curl command directly? By using the Linux like bash script, you now also need to install e.g. git on your machine. That does not make sense imho

Did not bother me to install git on the computer,
Which I also tried to put the curl command directly but failed
I have no prior knowledge with curl and exec commends

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.