-1

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).

Aserre
  • 4,916
  • 5
  • 33
  • 56
etiennnr
  • 305
  • 5
  • 12
  • try with `set -x` – KamilCuk Mar 27 '19 at 14:00
  • like this : curl -s set -x\ --header "X-Auth-Token: $OS_TOKEN" \ http://$1/image/v2/images ?? – etiennnr Mar 27 '19 at 14:04
  • 1
    add `set -x` to the beginning of the script, on the first line. Run. Observe the output. The lines starting `+` are commands that are executing. Search google on how to debug bash scripts. – KamilCuk Mar 27 '19 at 14:06

1 Answers1

0

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.

etiennnr
  • 305
  • 5
  • 12