我有一个包含 fqdn 和主机名变量的文本文件。文件看起来像这样
first_fqnd first_hostname
second_fqdn second_hostname
..... .....
我必须在 bash 脚本中使用 curl 更新一些数据,但我必须从这个文本文件中获取 fqdn 和主机名,并为每一对 fqdn 和主机名制作一个 curl。
我的 curl 应该是这样的:
curl -H "Content-Type:application/json" -XPUT "https://pup.pnet.pl/api/hosts/**fqdn from file**" -d '{"host":{"name": "**hostname from file**"}}' --cacert bundle.pem --cert xxx-pem.cer --key xxx-privkey.pem
如何将这些变量从文件传递到 curl?我想过使用awk,但我不知道如何在curl命令中使用它
最佳答案
使用 while
结构读取文件行并将空格分隔的参数作为两个相关变量,fqdn
和 hostn
:
while read fqdn hostn; do
curl -H .... -XPUT "https://pup.pnet.pl/api/hosts/${fqdn}" \
-d '{"host":{"name": "'"${hostn}"'"}}' --cacert ....; done <file.txt
关于bash - 如何在文件中使用 curl 命令数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38452857/