Linux Curl 命令重复 URL 请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12409519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Curl Command to Repeat URL Request
提问by mathematician
Whats the syntax for a linux command that hits a URL repeatedly, x number of times. I don't need to do anything with the data, I just need to replicate hitting refresh 20 times in a browser.
什么是重复点击 URL 的 linux 命令的语法,x 次。我不需要对数据做任何事情,我只需要在浏览器中复制点击刷新 20 次。
回答by matt b
for i in `seq 1 20`; do curl http://url; done
Or if you want to get timing information back, use ab
:
或者,如果您想获取计时信息,请使用ab
:
ab -n 20 http://url/
回答by Avichal Badaya
You might be interested in Apache Benchtool which is basically used to do simple load testing.
您可能对Apache Bench工具感兴趣,它基本上用于进行简单的负载测试。
example :
例子 :
ab -n 500 -c 20 http://www.example.com/
n = total number of request, c = number of concurrent request
n = 请求总数,c = 并发请求数
回答by alexm
You could use URL sequence substitution with a dummy query string (if you want to use CURL and save a few keystrokes):
您可以使用带有虚拟查询字符串的 URL 序列替换(如果您想使用 CURL 并保存几次击键):
curl http://www.myurl.com/?[1-20]
If you have other query strings in your URL, assign the sequence to a throwaway variable:
如果您的 URL 中有其他查询字符串,请将序列分配给一次性变量:
curl http://www.myurl.com/?myVar=111&fakeVar=[1-20]
Check out the URL section on the man page: https://curl.haxx.se/docs/manpage.html
查看手册页上的 URL 部分:https: //curl.haxx.se/docs/manpage.html
回答by Sharath Raghavan
If you want to add an interval before executing the cron the next time you can add a sleep
如果你想在下次执行 cron 之前添加一个间隔,你可以添加一个 sleep
for i in
{1..100}
; do echo $i && curl "http://URL" >> /tmp/output.log && sleep 120; done
因为我在
{1..100}
;做 echo $i && curl " http://URL" >> /tmp/output.log && sleep 120; 完毕
回答by Lazaro Fernandes Lima Suleiman
You can use any bash looping constructs like FOR
, with is compatible to Linux and Mac.
您可以使用任何 bash 循环结构,例如FOR
, with 与 Linux 和 Mac 兼容。
https://tiswww.case.edu/php/chet/bash/bashref.html#Looping-Constructs
https://tiswww.case.edu/php/chet/bash/bashref.html#Looping-Constructs
In your specific case you can define N
iterations, with N
is a number defining how many curl
executions you want.
在您的特定情况下,您可以定义N
迭代,用N
一个数字定义curl
您想要的执行次数。
for n in {1..N}; do curl <arguments>; done
ex:
前任:
for n in {1..20}; do curl -d @notification.json -H 'Content-Type: application/json' localhost:3000/dispatcher/notify; done