我创建了一个 cURL bash 脚本,我想在其中将响应主体保存到名为 output.log 的文件中,但是当我打开文件 output.log 时,它看起来像这样:
这是我的 bash 脚本:
#!/bin/bash
SECRET_KEY='helloWorld'
FILE_NAME='sma.txt'
function save_log()
{
printf '%s\n' \
"Header Code : $1" \
"Executed at : $(date)" \
"Response Body : $2" \
'==========================================================\n' > output.log
}
while IFS= read -r line;
do
HTTP_RESPONSE=$(curl -I -L -s -w "HTTPSTATUS:%{http_code}\\n" -H "X-Gitlab-Event: Push Hook" -H 'X-Gitlab-Token: '$SECRET_KEY --insecure $line 2>&1)
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
save_log $HTTP_STATUS $HTTP_RESPONSE
done < $FILE_NAME
谁能帮我在我的 output.log 中得到我想要的输出?
最佳答案
来自 Curl 文档: -I, --head 只显示文档信息 删除 -I 或将其替换为 -i 应该可以解决您的问题
关于linux - 在 bash 脚本中循环执行命令时,如何将来自 cURL 的响应主体保存在文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56787716/