[英]How to save the response body from cURL in a file when executing the command in a loop in a bash script?
I've created a cURL bash script in which I want to save the response body into a file called output.log , but when I open the file output.log it looks like this: 我创建了一个cURL bash脚本,其中要将响应正文保存到名为output.log的文件中 ,但是当我打开文件output.log时,它看起来像这样:
Here is my bash script: 这是我的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
Can anyone help me get my desired output in my output.log? 谁能帮助我在output.log中获得所需的输出?
从Curl文档中:-I,--head仅显示文档信息删除-I或将其替换为-i应该可以解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.