如何在一系列服务器IP(URL)上执行相同的curl请求 [英] How to execute the same curl request on a sequence of server IPs (URLs)
本文介绍了如何在一系列服务器IP(URL)上执行相同的curl请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
命令
curl -v -H "Accept: application/json" -H "Content-type: application/json" \
-X POST -d '{"test": "some data"}' http://XX.XX.X.001:8080/services/test
我想在不同的服务器(IP地址)上执行上述相同的curl命令.有什么方法或CURL命令,以便我可以在所有服务器上执行此服务,而不是每次都手动更改IP地址吗?
I want to execute the above same curl command on different servers (IP addresses). Is there any way or CURL command so I can execute this service on all servers, instead of changing the IP address every time manually?
我以某种顺序拥有服务器IP,例如
I have servers IP in some sequence, e.g.
http://XX.XX.X.002:8080/services/test
http://XX.XX.X.003:8080/services/test
...
推荐答案
您可以使用Shell的括号扩展,例如{2..15}
表示2,3,4,...,15
:
You can either use shell's brace expansion in bash
, e.g. {2..15}
for 2,3,4,...,15
:
curl ... http://x.x.x.{2..15}:8080/services/test
或curl
的字母数字系列[]
运算符在网址部分(请注意双引号):
or, curl
's alphanumeric series []
operator in the URL part (notice the double-quotes):
curl ... "http://x.x.x.[2-15]:8080/services/test"
或者,您可以使用算术for
循环:
Alternatively, you can use arithmetic for
loop:
for ((i=2; i<=15; i++)); do
curl ... "http://x.x.x.$i:8080/services/test"
done
这篇关于如何在一系列服务器IP(URL)上执行相同的curl请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文