Reputation: 57
I am running bash script with curl command in it. I read the username, password and url from a properties file. But when the command gets executed, the response gives me an error with saying you are not authorized to access this page. I print out the whole curl command and it is correct.
Here is the part of the code:
this gives me response saying not authorized:
curl -u $USERNAMEVAL:$PWDVAL $URLVAL
this works perfectly even from inside bash program:
curl -u test\\test:test www.blah.com
What could be the problem? Any help will be appreciated.
Upvotes: 0
Views: 1396
Reputation: 398
When I have a situation where a command in a Bash shell script fails yet the same command with what I think are the same parameters works when I manually run it, I suspect an issue with either the parameter values or the parameter quoting.
As an initial step in isolating the problem, I'd suggest that immediately before the line
curl -u $USERNAMEVAL:$PWDVAL $URLVAL
you add something such as
echo "curl -u $USERNAMEVAL:$PWDVAL $URLVAL"
Or even (to be very clear):
echo "\$USERNAMEVAL(${#USERNAMEVAL}): \"$USERNAMEVAL\""
echo "\$PWDVAL(${#PWDVAL}): \"$PWDVAL\""
echo "\$URLVAL(${#URLVAL}): \"$URLVAL\""
echo "curl -u $USERNAMEVAL:$PWDVAL $URLVAL"
This prints the name, length, and value of each of the variables being used to construct the curl
command.
E.g.:
#!/bin/bash
USERNAMEVAL='test\\test'
PWDVAL='test'
URLVAL='www.blah.com'
echo "\$USERNAMEVAL(${#USERNAMEVAL}): \"$USERNAMEVAL\""
echo "\$PWDVAL(${#PWDVAL}): \"$PWDVAL\""
echo "\$URLVAL(${#URLVAL}): \"$URLVAL\""
echo "curl -u $USERNAMEVAL:$PWDVAL $URLVAL"
This prints:
$USERNAMEVAL(10): "test\\test"
$PWDVAL(4): "test"
$URLVAL(12): "www.blah.com"
curl -u test\\test:test www.blah.com
Upvotes: 1