使用Shell脚本从文件测试其余Web服务时如何获取成功计数,失败计数和失败原因 [英] How to get success count, failure count and failure reason when testing rest webservices from file using shell script

查看:120
本文介绍了使用Shell脚本从文件测试其余Web服务时如何获取成功计数,失败计数和失败原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我通过具有多个if条件来使用Shell脚本测试Web服务,并且使用Shell脚本编码获取成功次数,失败次数和失败原因

Hi i am testing web services using shell script by having multiple if condition, with the shell script coding i am getting success count, failure count and failure reason

success=0
failure=0

if curl -s --head --request DELETE http://localhost/bimws/delete/deleteUser?email=pradeepkumarhe1989@gmail.com | grep "200 OK" > /dev/null; then 
  success=$((success+1))
else
echo "DeleteUser is not working"$'\r' >> serverLog.txt
  failure=$((failure+1))
fi

if curl -s --head  --request GET http://localhost/bimws/get/getUserDetails?email=anusha4saju@gmail.com | grep "200 OK" > /dev/null; then 
  success=$((success+1))
else
 curl -s --head  --request GET http://localhost/bimws/get/getUserDetails?email=anusha4saju@gmail.com > f1.txt
 echo "getUserDetails is not working"$'\r' >> serverLog.txt
  failure=$((failure+1))
fi

if curl -s -i -X POST -H "Content-Type:application/json"  http://localhost/bimws/post/addProjectLocationAddress -d '{"companyid":"10","projectid":"200","addresstypeid":"5","address":"1234 main st","city":"san jose","state":"CA","zip":"989898","country":"United States"}' | grep "200 OK" > /dev/null; then 
  success=$((success+1))
else
echo "addProjectLocationAddress is not working"$'\r' >> serverLog.txt
  failure=$((failure+1))
fi

echo $success Success
echo $failure failure

但是我期待从一个名为web_services.txt的文件中测试Web服务,该文件包含所有使用Shell脚本的Web服务,我如何执行以及成功计数,失败计数和失败原因

but i am looking forward to test the web services from a file like i have file called web_services.txt which contains all my web services using shell script how do i execute and success count, failure count and failure reason

web_services.txt

所有呼叫删除,获取和发布都是不同的

All are different calls delete,get and post

http://localhost/bimws/delete/deleteUser?email=pradeepkumarhe1989@gmail.com


http://localhost/bimws/get/getUserDetails?email=anusha4saju@gmail.com



http://localhost/bimws/post/addProjectLocationAddress -d '{"companyid":"10","projectid":"200","addresstypeid":"5","address":"1234 main st"
,"city":"san jose","state":"CA","zip":"989898","country":"United States"}'

推荐答案

首先,您当前的代码无法正确处理空行.您需要跳过这些.

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

您的行已包含shell命令.在他们身上curl缩没有任何意义.相反,您应该评估这些命令.

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

然后,您需要修改curl,以便通过添加-f来报告请求是否成功:

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

这篇关于使用Shell脚本从文件测试其余Web服务时如何获取成功计数,失败计数和失败原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆