Execute wget in a rule from a docker container

Hello

I am using openhab in a docker container and try to get a rule working. (Download a snapshot from a ip cam and sent it via pushover. )

but every time i trigger the rule i get an error. when i execute wget in the container it works. Dont know why it dont work :frowning:

rule

rule "Klingel Bild"

  when
     Item TestSW02 changed 
  then

  
    executeCommandLine("wget -O Frontdoor.jpg 'http://192.168.1.82/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=MYUSER&password=MYPASS' ")
    

    end

error

6:54:17.459 [WARN ] [org.openhab.core.io.net.exec.ExecUtil] - Error occurred when executing commandLine '[wget -O Frontdoor.jpg 'http://192.168.1.82/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=MYUSER&password=MYPASS' ]'
java.io.IOException: Cannot run program "wget -O Frontdoor.jpg 'http://192.168.1.82/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=neodata&password=kakarot_1973' ": error=2, No such file or directory
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1128) ~[?:?]
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1071) ~[?:?]
	at org.openhab.core.io.net.exec.ExecUtil.executeCommandLine(ExecUtil.java:59) [bundleFile:?]
	at org.openhab.core.model.script.actions.Exec.executeCommandLine(Exec.java:40) [bundleFile:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	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:1176) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1151) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1137) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:1082) [bundleFile:?]
	at org.openhab.core.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:151) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:992) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:955) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:236) [bundleFile:?]
	at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:459) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:240) [bundleFile:?]
	at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:202) [bundleFile:?]
	at org.openhab.core.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:80) [bundleFile:?]
	at org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine.eval(DSLScriptEngine.java:125) [bundleFile:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) [bundleFile:?]
	at java.util.Optional.ifPresent(Optional.java:183) [?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1179) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:987) [bundleFile:?]
	at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:89) [bundleFile:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	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: error=2, No such file or directory
	at java.lang.ProcessImpl.forkAndExec(Native Method) ~[?:?]
	at java.lang.ProcessImpl.<init>(ProcessImpl.java:340) ~[?:?]
	at java.lang.ProcessImpl.start(ProcessImpl.java:271) ~[?:?]
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1107) ~[?:?]
	... 35 more

Base on the error message I assume that you use OH3.
OH3 uses a different syntax then before in OH2.
In OH3 all parameters separated by space need to be a separate parameter in the call to executeCommandLine.
Besides that wen you want to return something to a variable you should/need to use the wait parameter.
See Actions | openHAB .

Thx i look into it

edit:// working now

rule "Klingel Bild"

  when
     Item TestSW02 changed 
  then

  
    executeCommandLine("wget", "-O Frontdoor.jpg", "http://192.168.1.82/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=MYUSER&password=MYPASS")
    

    end

Hi!

I’m also converting my rule from OH2.x to OH3, and I’m struggeling with creating the attachment.
My setup is also running in Docker atm, and my snapshot is stored in the userdata folder (in the container this is /openhab/userdata)
When I try to send the message

PushoverAction.sendAttachmentMessage(Doorbellmessage, Title, "FrontDoor.jpg", "image/jpeg")

I always get the message:

[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'doorbell' failed: Skip sending the message as file 'FrontDoor.jpg' does not exist.

I also tried with adding the full path (/openhab/userdata/FrontDoor.jpg), but doesn’t make any difference.

edit: found the mistake. my command for saving the snapshot was not complete correct and added a space in front of the filename…

executeCommandLine(Duration.ofSeconds(2), "wget", "-O", "FrontDoor.jpg", "http://user:pass@192.168.0.xx:xx/Streaming/Channels/1/picture")
2 Likes

Is this syntax for a HIKVision NVR? I’m converting over my OH2 rules to OH3 and I have similar syntax as you for OH2 but all in one line.

executeCommandLine(Duration.ofSeconds(60), "wget http://xxxxx:xxxxxxx@192.168.0.xx:81/ISAPI/Streaming/channels/701/picture -O /var/lib/openhab/pics/" + GarageDoorCam)

Best, Jay

You need to separate the command and all it’s arguments. Not doing that the whole string will be taken as a single command ( including the arguments ).
See https://www.openhab.org/docs/configuration/actions.html#scripts-with-parameters
Alternatively you can create a wrapper shell script but even then you seem to have GarageDoorCam as argument ( in case you don’t want to put it inside of the script ).