2017-11-13 3 views
0

nicht aufgelöst werden Ich habe dieses Bash-Skript, das ich verwende, um eine CSV-Datei zu lesen und meine Daten in Riak einzufügen.Curl: Host konnte mit Hilfe von riak

#!/bin/bash 
# Set "," as the field separator using $IFS 
# and read line by line using while read combo 
while IFS=',' read -r Num_Acc senc catv occutc obs obsm choc manv num_veh 
do 
eval curl -i -X POST http://127.0.0.1:8098/riak/vehicule -H "Content-Type:application/json" -d {"Num_Acc":"$Num_Acc","senc":$senc,"catv":"$catv","occutc":"$occutc","obs":"$obs","obsm":$obsm,"choc":$choc,"manv":"$manv","num_veh":"$num_veh"} 
done < vehicules_2016.csv 

Das Problem ist, dass ich diesen Fehler haben, und ich kown nicht, woher es kommen konnte:

curl: (6) Could not resolve host: senc 
curl: (6) Could not resolve host: catv 
curl: (6) Could not resolve host: occutc 
curl: (6) Could not resolve host: obs 
curl: (6) Could not resolve host: obsm 
curl: (6) Could not resolve host: choc 
curl: (6) Could not resolve host: manv 
curl: (3) Illegal characters found in URL 
HTTP/1.1 201 Created 
Vary: Accept-Encoding 
Server: MochiWeb/1.1 WebMachine/1.10.9 (cafe not found) 
Location: /riak/vehicule/NiuPBkgCFBaqUNhorovnBvix2ED 
Date: Mon, 13 Nov 2017 11:43:08 GMT 
Content-Type: application/json 
Content-Length: 0 

ich das Problem der json Syntax sein könnte denken.

Vielen Dank für Ihre Hilfe.

Antwort

0

Sie haben Ihre Daten zwischen entweder doppelte Anführungszeichen " und entkommen inneren Anführungszeichen wie \" oder auch heredoc können einschließen:

#!/bin/bash 
while IFS=',' read -r Num_Acc senc catv occutc obs obsm choc manv num_veh 
do 
data=$(cat <<EOF 
{ 
    "Num_Acc":"$Num_Acc", 
    "senc": "$senc", 
    "catv": "$catv", 
    "occutc": "$occutc", 
    "obs": "$obs", 
    "obsm": "$obsm", 
    "choc": "$choc", 
    "manv": "$manv", 
    "num_veh": "$num_veh" 
} 
EOF 
) 

curl -i http://127.0.0.1:8098/riak/vehicule \ 
    -H "Content-Type: application/json" \ 
    -d "$data" 

done < vehicules_2016.csv 

Scheck this post

Verwandte Themen