美文网首页
shell脚本批量调用接口

shell脚本批量调用接口

作者: 进击云原生 | 来源:发表于2018-04-14 10:17 被阅读1229次

  要求在页面查询到5000条数据,为了方便插入,用shell脚本写curl命令调用自己写的代码接口;

脚本如下:

#!/bin/bash
a=0
while [ $a -le 10 ]; do
 
  # length of ts is 13 required,Through the following way like this
  ts=`date +%s%N`      
  ts=${ts:0:13}
  
  json='{"name" : "'$1$a'", "age" : '$2', "ts" : '$ts'}'
  
  a=$((a+1))
  
  curl -k -H 'Content-Type:application/json;charset=utf-8' http://192.168.2.5:8080 -X POST -d "'$json'"

done
批量curl脚本

执行脚本

sh batch_curl.sh gege 21

执行结果

10次curl执行结果

该接口是用go语言提供的demo接口:如下:

  • 目录结构:


    目录结构
  • app.conf
copyrequestbody = true
  • controller.go
package controller

import (
    "github.com/astaxie/beego"
    "fmt"
)

type SayHelloController struct {
    beego.Controller
}

func (this *SayHelloController) SayHello(){

    fmt.Println("RequestBody is ", string(this.Ctx.Input.RequestBody))

    this.Ctx.Output.Header("Content-type", "application/json;charset=utf-8")
    this.Ctx.Output.SetStatus(200)
    this.Ctx.Output.Body(this.Ctx.Input.RequestBody)
}
  • router.go
package router

import (
    "github.com/astaxie/beego"
    "sayHello/controller"
)

var hello = controller.SayHelloController{}

func init() {

    beego.Router("/", &hello, "POST:SayHello")
}
  • main.go
package main

import (
    "github.com/astaxie/beego"
    _ "sayHello/router"
    "fmt"
)

func main() {
    fmt.Println(beego.BConfig.CopyRequestBody)
    beego.Run()
}

相关文章

  • shell脚本批量调用接口

      要求在页面查询到5000条数据,为了方便插入,用shell脚本写curl命令调用自己写的代码接口; 脚本如下:...

  • (转)iOS使用shell脚本批量修改属性

    iOS使用shell脚本注入混淆内容iOS使用Shell脚本批量修改类名称iOS使用shell脚本批量修改属性 h...

  • 【Php】接口里调用system()无反应

    最开始写了个简单接口,通过system() 调用shell命令。发现shell脚本并没有执行。百度了一番说有可能跟...

  • Python 入门

    Python 调用 Shell 脚本 准备 shell 脚本 hello.sh 使用os.system方法 输出结...

  • spark程序中调用shell脚本

    scala直接调用shell脚本是不行的,但是可以利用java调用shell脚本然后在spark代码中引入java...

  • [Linux]Shell

    shell:命令解释器,驱动linux内核;应用程序调用shell命令 1.Shell脚本的执行方式 脚本格式要求...

  • 宝塔crontab使用笔记!

    Shell脚本 选择Shell脚本,执行周期设置每月17日9时0分,脚本内容是使用微信消息模板批量推送,用户数据太...

  • 脚本学习

    [Android------Android.mk调用shell脚本 (shell ($(LOCAL_PATH)/e...

  • Python--Linux服务器基于SVN的自动部署

    整体实现思路: 1. python编写http接口(需要开机自启)2.python中调用shell3.sh脚本中编...

  • Shell编程--case,for,while,until

    shell多分支case语句 for循环 语法一: 批量压缩文件脚本 语法二: 从1加到100 批量添加用户 批量...

网友评论

      本文标题:shell脚本批量调用接口

      本文链接:https://www.haomeiwen.com/subject/naikkftx.html