0

I am communicating with HDFS using curl. Procedure to interact with HDFS via webhdfs is two steps and I receive a url from a first curl command:

create_request=$(curl -i -X PUT "http:/somewhere:50070/webhdfs/v1/${path}?op=CREATE")

destination=$(echo "$create_request" | grep Location | cut -d " " -f 2)

Using the destination variable, I can upload my file with the following:

curl -i -X PUT -T $local_file_path "$destination"

However, the above commands throws :

curl: (3) URL using bad/illegal format or missing URL

Using the exact same command but changing $destination bby the URL it contains (writting it manually) works file.

Why do I have this problem and how to solve this ?

PS: $destination does contain the data: http://datanode:50075/webhdfs/v1/path/test/file.jar?op=CREATE&namenoderpcaddress=cluster&overwrite=false


Edit: Quoting

path="mypath"
local_file_path="untitled.txt"

create_request="$(curl -i -X PUT "http://ip:50070/webhdfs/v1/${path}?op=CREATE")"

destination="$(echo "$create_request" | grep "Location"| cut -d ' ' -f 2)"

curl -i -X PUT -T "$local_file_path" "$destination"

Gives the same error message.

Itération 122442
  • 1,911
  • 19
  • 51

1 Answers1

2

You get a \r (carriage return) back in $destination. You can remove it with tr -d '\r'

destination=$(echo "$create_request" | grep Location | cut -d " " -f 2 | tr -d '\r')
Ted Lyngmo
  • 60,763
  • 5
  • 37
  • 77
  • Wow. Right. Did you understand that from the diff result ? Is carriage return the only possible reason that the diff says there is a difference while not showing it ? – Itération 122442 Apr 22 '21 at 14:56
  • 1
    @FlorianCastelain I actually misread the output :-) I thought the diff output was the raw output from my `>$destinationdest – Ted Lyngmo Apr 22 '21 at 14:57