I don’t know how I missed the colon. unfortunately, that didn’t fix it. I made sure that the user and password, and all other variables are correct.
new code
#!/bin/sh
cookie=$(mktemp)
headers=$(mktemp)
curl_cmd="curl --silent --output /dev/null --cookie ${cookie} --cookie-jar ${cookie} --insecure"
# generate new password
NEW_PWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# generate QR code
wget --output-document="/config/www/${5}.png" "http://api.qrserver.com/v1/create-qr-code/?data=WIFI:T:WPA;S:${5};P:${NEW_PWD};H:;&size=100x100"
# authenticate against unifi controller
${curl_cmd} -H 'Content-Type: application/json' -D ${headers} -d "{\"username\":\"${1}\", \"password\":\"${2}\"}" https://${3}:8443/api/login
# change wifi password
${curl_cmd} -k -X PUT https://${3}:8443/api/s/default/rest/wlanconf/${4} -H "Content-Type: application/json" -d "{\"_id\":\"${4}\",\"x_passphrase\":\"${NEW_PWD}\"}"
error
stdout: ""
stderr: "/config/scripts/wifichange.sh: line 2: $'\\r': command not found\n/config/scripts/wifichange.sh: line 5: $'\\r': command not found\n/config/scripts/wifichange.sh: line 7: $'\\r': command not found\n/config/scripts/wifichange.sh: line 10: $'\\r': command not found\nConnecting to api.qrserver.com (95.216.163.127:80)\nwget: server returned error: HTTP/1.1 400 Bad Request\n/config/scripts/wifichange.sh: line 13: $'\\r': command not found\ncurl: option --insecure\r: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information\n/config/scripts/wifichange.sh: line 16: $'\\r': command not found\ncurl: option --insecure\r: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information"
returncode: 2
in my troubleshooting, I hardcoded the variable’s values and got the same error. then removed the unifi portion of the code and got this error
stdout: ""
stderr: |-
/config/scripts/wifichange.sh: line 2: $'\r': command not found
/config/scripts/wifichange.sh: line 5: $'\r': command not found
/config/scripts/wifichange.sh: line 7: $'\r': command not found
/config/scripts/wifichange.sh: line 10: $'\r': command not found
Connecting to api.qrserver.com (159.69.246.187:80)
wget: server returned error: HTTP/1.1 400 Bad Request
/config/scripts/wifichange.sh: line 13: $'\r': command not found
/config/scripts/wifichange.sh: line 16: $'\r': command not found
returncode: 127
I don’t know but it seems to me that the problem is in the QR code part