shell脚本测试基本的接口

1. 首先需要创建一个.sh文件 vi myshell.sh

2.编辑myshell.sh文件

注意变量定义的时候 不要有空格,要不然不生效

1 #!/bin/sh
2 json_request='{"name":"XX","age":"10"}'
3 hostUrl='http://XXX/XX/XX'
4 post_date=`curl -X POST -H 'content-type:application/json' -d $json_request $hostUrl`#call接口
5 #success=`cat resJson|awk -F"[success]" '/success/{print$3}'`
6 # echo 'the value is' $success
7 for i in {1..10} #for循环从1到10
8 do
9 #if [$post_date =~ "status" || $post_date =~ "true"];then
10 echo "---------------json response----------------- "$i $post_date
11 # echo "----success-----"
12 #else
13 # echo $post_date
14 # echo "----fail-----"
15 #fi
16 done
17

3.给刚创建的文件建立一个可以执行的权限

chmod +x myshell.sh

4.执行脚本

sh myshell.sh

猜你喜欢

转载自www.cnblogs.com/echo777/p/12678540.html