How to get success count, failure count and failure reason when testing rest webservices from file using shell script

孤街醉人 提交于 2019-12-04 20:33:43

First of all, your current code does not correctly deal with empty lines. You need to skip those.

Your lines already contain shell commands. Running curl on them makes no sense. Instead, you should evaluate these commands.

Then, you need to modify curl so that it reports whether the request was successful by adding -f:

FILE=D:/WS.txt
success=0
failure=0
while read LINE; do
    if test -z "$LINE"; then
        continue
    fi
    if eval $(echo "$LINE" | sed 's/^curl/curl -f -s/') > /dev/null; then 
        success=$((success+1))
    else
        echo $LINE >> aNewFile.txt
        failure=$((failure+1))
    fi
done < $FILE
echo $success Success
echo $failure failure
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!