0

I have written the shell script below should be the expected out put

{"lastChecked":1582765938951,"entry":"10.123.45.67:9082","canConnect":true,"httpStatus":0,"httpProxy":null,"responseTime":1,"validUrl":false,"validHostname":true}

When I am trying to execute it was throwing an error

{"timestamp":1582765411548,"status":500,"error":"Internal Server Error","exception":"org.json.JSONException","message":"Missing value at 10 [character 11 line 1]","path":"/v2/willitconnect"}

if I put echo in front of curl, then I can it is printing the host and port numbers, once I remove echo then it is not giving me the expected output

This is the script which I have written

#!/bin/bash
# Purpose: Read Comma Separated CSV File
INPUT=Hostnport.csv
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read hostname port 
do
     echo "hostname : $hostname"
     echo "port : $port"
     curl -s -k --location --request POST 'https://willitconnect.apps.px-npe01b.cf.t-mobile.com/v2/willitconnect' \
--header 'Content-Type: application/json' 
--data-raw {\"target\": \"$hostname:$port\"}\'
done < Hostnport.csv
IFS=$OLDIFS
Drew
  • 3,814
  • 2
  • 9
  • 28
  • I miss backslash at the end of your --header row and `\'` is not necessary. Check https://stackoverflow.com/questions/17029902/using-curl-post-with-variables-defined-in-bash-script-functions – lojza Feb 27 '20 at 17:11
  • If i remove \' then it is not printing the host and port values instead its printing {\"target\": \"$hostname:$port\"}, if add \' then it is printing expected value. I had back slash end of --header row, some typo error. – Kalpana Pinninty Feb 27 '20 at 18:56

0 Answers0