Command
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
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?
I have servers IP in some sequence, eg
http://XX.XX.X.002:8080/services/test
http://XX.XX.X.003:8080/services/test
...
You can either use shell's brace expansion in bash
, eg {2..15}
for 2,3,4,...,15
:
curl ... http://x.x.x.{2..15}:8080/services/test
or, curl
's alphanumeric series []
operator in the URL part (notice the double-quotes):
curl ... "http://x.x.x.[2-15]:8080/services/test"
Alternatively, you can use arithmetic for
loop:
for ((i=2; i<=15; i++)); do
curl ... "http://x.x.x.$i:8080/services/test"
done
You could use a loop:
for HOST in 0.0.0.1:8080 0.0.0.2:8080; do curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"my": "data"}' http://$HOST/services/test ; done
If your hosts are sequential then randomir's answer is a lot cleaner.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.