我有一个这样的 bash 脚本
#!/bin/bash
while read fqdn hostname; do
curl -H "Content-Type:application/json" -XPUT "https://server/api/hosts/${fqdn}" -d '{"host":{"name": "'${hostname}'"}}' --cacert bundle.pem --cert pnet-pem.cer --key privkey.pem
done <curl1.txt
文件 curl1.txt 包含
fqdn(选项卡)主机名
…………
我必须使用 Foreman API 更新一些数据。我有很多 fqdns 和主机名,所以我编写了上面的脚本。问题出在 JSON 上,因为我收到如下错误:
{"status":400,"error":"There was a problem in the JSON you submitted: 795: unexpected token at '{\"host\":{\"name\": \"ptesrv02-lub\r\"}}'"}
当我'{"host":{"name": "${hostname}"}}'
代替时'{"host":{"name": "'${hostname}'"}}'
,我得到
{
"error": {"id":130,"errors":{"interfaces.name":["is invalid"],"name":["is invalid"]},"full_messages":["Name is invalid","Name is invalid"]}
}
那么问题出在哪里?你能帮我吗?