I'm building a script to change between the day and night profiles on my IP cameras using sunwait.
When I use the following curl command on the command-line, curl returns OK and the camera changes to the specific profile.
curl -v -s -g --digest -u admin:admin "h
ttp://*IP*/cgi-bin/configManager.cgi?action=setConfig&VideoI
nMode[0].Config[0]=0"
When I run the exact same command in a script, I get:
* URL rejected: Error
3
This is the script:
#/bin/sh
curl -v -s -g --digest -u admin:admin "h
ttp://*IP*/cgi-bin/configManager.cgi?action=setConfig&VideoI
nMode[0].Config[0]=0"
echo $?
I'm sure that it's a syntax error, I'm just struggling to find it.
evs
October 23, 2024, 7:34pm
3
Just to sanity check, are you doing this curl command in multiple lines or single line in your shell script?
edit:
here's example to replicate problem?
root@OpenWrt-RT3200:/tmp# ./example.sh
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT" />
<meta http-equiv="refresh" content="0; URL=cgi-bin/luci/" />
<style type="text/css">
body { background: white; font-family: arial, helvetica, sans-serif; }
a { color: black; }
@media (prefers-color-scheme: dark) {
body { background: black; }
a { color: white; }
}
</style>
</head>
<body>
<a href="cgi-bin/luci/">LuCI - Lua Configuration Interface</a>
</body>
</html>
root@OpenWrt-RT3200:/tmp# cat example.sh
curl http://localhost
root@OpenWrt-RT3200:/tmp# vi example2.sh
root@OpenWrt-RT3200:/tmp# chmod +x example2.sh
root@OpenWrt-RT3200:/tmp# ./example2.sh
curl: (3) URL rejected: Error
root@OpenWrt-RT3200:/tmp#
root@OpenWrt-RT3200:/tmp# cat example2.sh
curl "h
ttp://localhost"
root@OpenWrt-RT3200:/tmp#
2 Likes
Just trying one line to get the syntax correct. There will be approximately 16 cameras having their profile changed. Exact same command save for different IPs
1 Like
evs
October 23, 2024, 7:42pm
5
Yeah note the two things. example.sh and example2.sh
I think it's line breaks in your shell script file, without using a backslash "\" at the end?
Thank you for pointing that out. No success unfortunately.
Try changing the double quotes to single quotes, to avoid any possible expansion.
Added line breaks. No success.
#!/bin/sh
curl -v -s -g --digest -u admin:admin "h
ttp://*IP*/cgi-bin/configManager.cgi?action=setConfig&VideoI
nMode[0].Config[0]=0" \
echo $?
Changed to single quotes. No success.
#!/bin/sh
curl -v -s -g --digest -u admin:admin 'h
ttp://*IP*/cgi-bin/configManager.cgi?action=setConfig&VideoI
nMode[0].Config[0]=0' \
echo $?
evs
October 23, 2024, 7:48pm
10
Ok I need to clarify further sorry. You need a backslash at the end of each line (you are breaking, except the last one which doesn't go to the next line) to set up a multiple line shell script?
#!/bin/sh
curl -v -s -g --digest -u admin:admin "h\
ttp://*IP*/cgi-bin/configManager.cgi?action=setConfig&VideoI\
nMode[0].Config[0]=0"
echo $?
edit to keep with my minimal example:
root@OpenWrt-RT3200:/tmp# ./example3.sh
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/8.7.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Keep-Alive: timeout=20
< ETag: "521-346-66f16066"
< Last-Modified: Mon, 23 Sep 2024 12:34:46 GMT
< Date: Wed, 23 Oct 2024 19:49:59 GMT
< Content-Type: text/html
< Content-Length: 838
<
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT" />
<meta http-equiv="refresh" content="0; URL=cgi-bin/luci/" />
<style type="text/css">
body { background: white; font-family: arial, helvetica, sans-serif; }
a { color: black; }
@media (prefers-color-scheme: dark) {
body { background: black; }
a { color: white; }
}
</style>
</head>
<body>
<a href="cgi-bin/luci/">LuCI - Lua Configuration Interface</a>
</body>
</html>
0
root@OpenWrt-RT3200:/tmp# cat example3.sh
#!/bin/sh
curl -v -s -g --digest -u admin:admin "h\
ttp://localhost"
echo $?
root@OpenWrt-RT3200:/tmp#
1 Like
#!/bin/sh
USERNAME="admin"
PASSWORD="admin"
IP="..."
VINDEX=0
CINDEX=0
URL="http://$IP/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[$VINDEX].Config[$CINDEX]=0"
echo "$URL"
curl -v -s -g --digest -u "$USERNAME:$PASSWORD" "$URL"
echo $?
3 Likes
evs
October 23, 2024, 7:53pm
12
The keyword you're after is "line continuation"
2 Likes
Ok, it appears to be working. I had accidentally added a line break in. Once I moved the curl command back to one line, it appears to have worked.
This is what I currently have:
#!/bin/sh
curl -v -s -g --digest -u admin:admin "http://*IP*/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1" \
Oddly, the command is working but I'm still getting an error from curl. This is the output:
> GET /cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1 HTTP/1.1
> Host: *IP*
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< WWW-Authenticate: Digest realm="Login to 0ee37b6940fab458861babf90f03d48f", qop="auth", nonce="640130221", opaque="b481d2d8491118a2282867c858406c4677ffb871"
< Connection: close
< CONTENT-LENGTH: 0
<
> GET /cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1 HTTP/1.1
> Host: *IP*
> Authorization: Digest username="admin", realm="Login to 0ee37b6940fab458861babf90f03d48f", nonce="640130221", uri="/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1", cnonce="NDY5NDJmMTBhMWM4ZjhiNzE2MGFmYjUxMGUwNjc3MDA=", nc=00000001, qop=auth, response="b062d5b50f526e044ee2de3d7573f899", opaque="b481d2d8491118a2282867c858406c4677ffb871"
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 200 OK
< X-XSS-Protection: 1;mode=block
< X-Frame-Options: SAMEORIGIN
< Content-Security-Policy: script-src 'self' 'unsafe-inline' 'unsafe-eval'
< Strict-Transport-Security: max-age=604800; includeSubDomains
< Content-type: text/plain;charset=utf-8
< CONNECTION: close
< CONTENT-LENGTH: 4
<
OK
* URL rejected: Error
But it works so I'll take it.
Thank you to everyone for your help!
1 Like
If it's just one line, you don't want to suffix it with '\'.
The error happens because it's trying to build and access a second URL from that.
P.S. You should mark @evs response as the solution. I just provided an example that shows that better code organization and structuring will help avoid bugs like these.
2 Likes
evs
October 23, 2024, 8:15pm
15
Hahaha thanks @Cthulhu88 I don't mind. You did give a well written response too =)
system
Closed
November 2, 2024, 8:15pm
16
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.