我的shell脚本如下所示:
#!/bin/bash
curl -f -T /home/skript_1.txt -u XXX:XXXXXXX! -k http://192.168.0.100/home/test.txt
res=$?
if test "$res" != 0; then
echo "the curl command failed with: $res"
else
echo "Success $res"
fi我用这个来填充文件..。
现在我的问题是,我不能得到所有的错误。举个例子,如果我输入了一个错误的URL (正确的URL是http://192.168.0.100:5005/home/test.txt),上传失败,但退出代码仍然是0。
下面是带有错误URL的输出:
<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
Success 0我怎样才能得到这些错误呢?
我还对cURL和ftp目标做了同样的尝试,在那里它可以处理所有的错误。
发布于 2018-11-20 13:30:25
-w 'http_code %{http_code}'将使curl在输出的末尾添加HTTP代码。
也许您可以选择这个新版本,我只对它进行了部分测试:
#!/bin/bash
serverResponse=$(curl -f -w 'http_code %{http_code}' -T /home/skript_1.txt -u XXX:XXXXXXX! -k http://192.168.0.100/home/test.txt)
res=$?
if test "$res" != 0; then
printf "the curl command failed with: %s\n" "${res}"
else
http_code="${serverResponse##*http_code }"
if [[ ! -z "${http_code}" && "${http_code}" -ne 200 ]] ; then
printf "Server sent back this http status: %s\n" "${http_code}"
else
printf "Success %s\n" "${res}"
fi
fihttps://stackoverflow.com/questions/53393174
复制相似问题