开发者

Get cURL response in bash

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜