开发者

Get cURL response in bash

开发者 https://www.devze.com 2023-04-11 01:17 出处:网络
I开发者_运维知识库 have a simple bash script that uploads files to an FTP. I was wondering how to get a response from curl that I can record (error or success)?

I开发者_运维知识库 have a simple bash script that uploads files to an FTP. I was wondering how to get a response from curl that I can record (error or success)?

eval curl -T "${xmlFolder}"/"${xmlFile}" "${mediaFTP}"

Thanks in advance


Given the command provided, this should suffice:

curl -T "$xmlFolder/$xmlFile" "$mediaFTP" || 
  printf '%s\n' $?

Or, if you want to discard the error message:

curl -T "$xmlFolder/$xmlFile" "$mediaFTP" >/dev/null || 
  printf '%s\n' $?


The $? bash variable indicates success (val 0) / failure (val non 0) of the previous command. So you could do:

eval curl -T "${xmlFolder}"/"${xmlFile}" "${mediaFTP}"
err=$?
if [ $err -ne 0 ]
then
    echo "Failed with error code $err"
    exit
fi
0

精彩评论

暂无评论...
验证码 换一张
取 消