CURL:如何运行单个curl命令100次?

use*_*310 2 curl

我有以下curl命令:curl -i -H“内容类型:文本/纯文本” -X POST -d @hundredencoded http:/// aaa / bbb / message

对于负载测试,我需要运行此命令100次,我该如何使用CURL呢?

提前致谢。

Dav*_*viv 7

尽管该问题指定使用 curl 来完成此任务,但我强烈建议为此使用 ab。

ab (Apache Benchmark) 是专门针对相关案例构建的工具。它允许您多次调用特定请求并定义并发性。 http://httpd.apache.org/docs/2.0/programs/ab.html

您的测试将是:

ab -p post.txt -H 'Content-Type: text/plain' -n 100 -c 1 http://aaa/bbb/message
Run Code Online (Sandbox Code Playgroud)

或者,甚至更短:

ab -p post.txt -T text/plain -n 100 -c 1 http://aaa/bbb/message
Run Code Online (Sandbox Code Playgroud)

文件post.txt保存 POST 数据的位置。


qwr*_*qwr 6

嗨,尝试以下脚本代码(对不起,未经测试,让我知道它是否不起作用):将其另存为run.sh。那么你可以运行./run.sh 100,它只会同时执行。

#!/bin/bash

 for i in $(eval echo {1..$1})
 do 
  curl -i -H 'Content-Type: text/plain' -X POST -d @hundredencoded http:///aaa/bbb/message &
#gnome-terminal -x bash -c "curl -i -H 'Content-Type: text/plain' -X POST -d @hundredencoded http:///aaa/bbb/message ;bash"  

done
Run Code Online (Sandbox Code Playgroud)