I'm presently doing a shell script to create some networks / VMs on Openstack. Here, I'm first getting the token and then I'm trying to list all images. However, there seems to be some kind of problem with an environment variable
echo "GETTING TOKEN"
res=$( curl -sD - -o /dev/null \
-H "Content-Type: application/json" \
-d '
...
}' \
http://$1/identity/v3/auth/tokens)
token=$(echo "$res" | awk '/X-Subject-Token: /{print $NF}')
export OS_TOKEN="$token"
echo $OS_TOKEN
echo "X-Auth-Token: $OS_TOKEN"
curl -s \
--header "X-Auth-Token: $OS_TOKEN" \
http://$1/image/v2/images
this is the output that i'm getting :
devstack@MFZhani:~$ ./script.sh localhost
GETTING TOKEN
THE TOKEN
X-Auth-Token: THE SAME TOKEN
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.27 (Ubuntu) Server at 127.0.0.1 Port 80</address>
</body></html>
The thing is, when I hardcode the token, it works. Also, I know it's not caused by a bad character in the variable because I'm doing other commands with the exact same token for creating networks and it works just fine (the difference here is that i'm doing a GET instead of a POST).
Found it with the set -x
suggested by Kamil Cuk. There was a \r that I was not able to see otherwise. Deleted it and it worked. Thanks.