Problemas com Curl e Variáveis

0

Estou tentando fazer algo assim:

#!/bin/bash
for (( ; ; ))
do
IP="$(
    curl -s http://whatismijnip.nl |cut -d " " -f 5
)"
curl -X PUT "https://api.cloudflare.com/client/v4/zones/fc4a89d0f0a71df7969d3f6d32ef5c61/dns_records/dfa4ae7f9d7b99745a6a09e40c12b7f5" 
-H "Content-Type:application/json" 
-H "X-Auth-Key: U Dont Have To Know This" 
-H "X-Auth-Email:[email protected]" 
-d "{"id":"dfa4ae7f9d7b99745a6a09e40c12b7f5","type":"A","name":"ts.javelcraft.com","content":"'"$IP"'","proxiable":true,"proxied":false,"ttl":1,"locked":false,"zone_id":"fc4a89d0f0a71df7969d3f6d32ef5c61","zone_name":"javelcraft.com","created_on":"0000-00-00T00:00:00.000000Z","modified_on":"0000-00-00T00:00:00.000000Z","data":{}}"
done
pause

Mas isso retorna este erro:

{"success":false,"errors":[{"code":6007,"message":"Malformed JSON in request body"}],"messages":[],"result":null}

O que significa que o texto do json que está "" após -d é escrito incorretamente.

    
por Theshark556 04.10.2016 / 03:21

1 resposta

0

Tente isto:

#!/bin/bash
for (( ; ; ))
do
    IP="$(
        curl -s http://whatismijnip.nl |cut -d " " -f 5
    )"
    #
    JSONSTRING='{"id":"dfa4ae7f9d7b99745a6a09e40c12b7f5","type":"A","name":"ts.javelcraft.com","content":"'$IP'","proxiable":true,"proxied":false,"ttl":1,"locked":false,"zone_id":"fc4a89d0f0a71df7969d3f6d32ef5c61","zone_name":"javelcraft.com","created_on":"0000-00-00T00:00:00.000000Z","modified_on":"0000-00-00T00:00:00.000000Z","data":{}}'
    #
    curl -X PUT "https://api.cloudflare.com/client/v4/zones/fc4a89d0f0a71df7969d3f6d32ef5c61/dns_records/dfa4ae7f9d7b99745a6a09e40c12b7f5" 
        -H "Content-Type:application/json" 
        -H "X-Auth-Key: U Dont Have To Know This" 
        -H "X-Auth-Email:[email protected]" 
        -d $JSONSTRING

    # PRINT PRETTY JSON FORMAT
    echo $JSONSTRING | python -mjson.tool
done
pause
    
por bistoco 04.10.2016 / 19:08