Curl --anyauth -u user:pass http://ip/ as OH2 rule

Hi,
from raspbian command line this is working:
curl --anyauth -u root:pw ‘http://192.168.100.9:80/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1

Without --anyauth curl answers “UNAUTHORIZED” and ended not correctly

Openhab2 rule:

rule "ALARM ARMED OFF"
when
Item JA65_Home changed from OPEN to CLOSED
then
sendHttpGetRequest(“http://192.168.100.9:80/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1”)
end

does not work.

How can be --anyauth implemented ?
Thanks.

Call curl using executeCommandLine.

Many thanks Rich.
But still not working. Must be a rule of \ or ’ or " in the statement.

NOK
executeCommandLine("curl --anyauth -u root:pw 'http://192.168.100.9:80/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1'")

NOK - with \ before ’
executeCommandLine("curl --anyauth -u root:pw \'http://192.168.100.9:80/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1\'")

NOK -with \ before ’ and "
executeCommandLine(\"curl --anyauth -u root:pw \'http://192.168.100.9:80/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1\'\")

In karaf
log:tail exec
i can see:
10:44:22.180 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'curl --anyauth -u root:pw 'http://192.168.100.9:80/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1''

with double ’ on end

but the variable is still not deactivated.

From curl direct all OK.
curl --anyauth -u root:pw 'http://192.168.100.9:80/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1'

I can’t solve this for a couple of days. Thanks for any help.

I don’t have an answer for your issue using the command line but I would remove your password from your post.

1 Like

Try to replace spaces with @@ characters, e.g.

executeCommandLine("/usr/local/bin/speedtest-cli@@--simple", 120*1000)

All the spaces, like this:
executeCommandLine("curl@@--anyauth@@-u@@root:pw@@'http://192.168.100.9:80/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1'")

I’m not sure if ' character should be escaped too.

Cheers

1 Like

Thank you very much Kuba.
This solves my problem no ’ single quotas :0) and space to @@
curl statement should be as a string without spaces and ’

executeCommandLine("curl@@--anyauth@@-u@@root:pw@@http://192.168.100.9:80/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1")

Add a timeout to the call to executeCommandLine and save and log the result of the call so you can see exactly what curl is complaining about.

val result = executeCommandLine("curl ...", 5000)
logInfo("test", result)

That could more easily pinpoint your problem rather than trial and error.

Sometimes you have to double escape the escapes: i.e. \\' to get it to pass through the multiple parsers between your rule and the command line.

Does curl actually require the URL to be in quotes? You might be able to bypass this issue entirely if not.

Hi Rich,
thaks for help. Solution from Kuba works. Curl doesn’t require the URL quotes.
I found this article on github to:
https://github.com/openhab/openhab1-addons/wiki/Samples-Tricks#how-to-use-the-lifx-beta-api-via-executecommandline-and-curl
Maybe usefull for other user.

1 Like

good evening,

I have the problem that the command cannot be executed from the command line.

the link works with the browser.

does something have to be released in the Axis camera?

Greetings Michael

What’s your command?