Json Ip:使用shell脚本进行端口连接测试

Json Ip:使用shell脚本进行端口连接测试,json,shell,Json,Shell,我已经写了下面的shell脚本,应该是预期的输出 {“lastChecked”:1582765938951,“条目”:“10.123.45.67:9082”,“canConnect”:true,“httpStatus”:0,“httpProxy”:null,“responseTime”:1,“validUrl”:false,“validHostname”:true} 当我试图执行时,它抛出了一个错误 {“timestamp”:1582765411548,“status”:500,“error”:

我已经写了下面的shell脚本,应该是预期的输出

{“lastChecked”:1582765938951,“条目”:“10.123.45.67:9082”,“canConnect”:true,“httpStatus”:0,“httpProxy”:null,“responseTime”:1,“validUrl”:false,“validHostname”:true}

当我试图执行时,它抛出了一个错误

{“timestamp”:1582765411548,“status”:500,“error”:“Internal Server error”,“exception”:“org.json.jsoneexception”,“message”:“10处缺少值[字符11第1行],“path”:“/v2/willitconnect”}

如果我将
echo
放在
curl
前面,那么我可以确定它正在打印主机和端口号,一旦我删除echo,它就不会给我预期的输出

这是我写的剧本

#!/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
#/bin/bash
#用途:读取逗号分隔的CSV文件
输入=Hostnport.csv
OLDIFS=$IFS
如果s=','
[!-f$INPUT]&&&{echo“$INPUT文件未找到”;退出99;}
读取主机名端口时
做
echo“主机名:$hostname”
回显“端口:$port”
curl-s-k--location--request POST'https://willitconnect.apps.px-npe01b.cf.t-mobile.com/v2/willitconnect' \
--标题“内容类型:应用程序/json”
--原始数据{\“target\”:\“$hostname:$port\”}
完成
我忽略了--header行末尾的反斜杠,因此不需要使用
\'
。检查是否删除\'则它不打印主机和端口值,而是打印{\“target\”:\“$hostname:$port\”},如果添加\'则它打印预期值。我有反斜杠结尾的标题行,一些打字错误。