将curl 与命令文件一起使用

发布于 2024-12-26 02:23:14 字数 2084 浏览 1 评论 0原文

我正在使用 BASH shell 中的curl。我想创建一个通过curl 发送的命令文本文件,然后以某种方式让所有命令同时运行。我已经很长时间没有处理 UNIX 命令了,但是有人可以告诉我如何完成这个任务吗(假设我创建了一个名为commands.txt 的文件)?

编辑这篇文章以包含我想批量执行的命令文件的示例......

curl -XPUT 'http://localhost:9200/foo/property/1' -d '{"firstName":"Domino","lastName":"Derval"}'
curl -XPUT 'http://localhost:9200/foo/property/2' -d '{"firstName":"Elektra","lastName":"King"}'
curl -XPUT 'http://localhost:9200/foo/property/3' -d '{"firstName":"Fiona","lastName":"Volpe"}'
curl -XPUT 'http://localhost:9200/foo/property/4' -d '{"firstName":"Holly","lastName":"Goodhead"}'
curl -XPUT 'http://localhost:9200/foo/property/5' -d '{"firstName":"Honey","lastName":"Rider"}'
curl -XPUT 'http://localhost:9200/foo/property/6' -d '{"firstName":"Jill","lastName":"Masterton"}'
curl -XPUT 'http://localhost:9200/foo/property/7' -d '{"firstName":"Kissy","lastName":"Suzuki"}'
curl -XPUT 'http://localhost:9200/foo/property/8' -d '{"firstName":"Mary","lastName":"Goodnight"}'
curl -XPUT 'http://localhost:9200/foo/property/9' -d '{"firstName":"Miranda","lastName":"Frost"}'
curl -XPUT 'http://localhost:9200/foo/property/10' -d '{"firstName":"Molly","lastName":"Warmflash"}'
curl -XPUT 'http://localhost:9200/foo/property/11' -d '{"firstName":"Paula","lastName":"Caplan"}'
curl -XPUT 'http://localhost:9200/foo/property/12' -d '{"firstName":"Penelope","lastName":"Smallbone"}'
curl -XPUT 'http://localhost:9200/foo/property/13' -d '{"firstName":"Pussy","lastName":"Galore"}'
curl -XPUT 'http://localhost:9200/foo/property/14' -d '{"firstName":"Strawberry","lastName":"Fields"}'
curl -XPUT 'http://localhost:9200/foo/property/15' -d '{"firstName":"Sylvia","lastName":"Trench"}'
curl -XPUT 'http://localhost:9200/foo/property/16' -d '{"firstName":"Tatiana","lastName":"Romanova"}'
curl -XPUT 'http://localhost:9200/foo/property/17' -d '{"firstName":"Tilly","lastName":"Masterton"}'
curl -XPUT 'http://localhost:9200/foo/property/18' -d '{"firstName":"Vesper","lastName":"Lynd"}'
curl -XPUT 'http://localhost:9200/foo/property/19' -d '{"firstName":"Xenia","lastName":"Onatopp"}'

I am using curl from a BASH shell. I would like to create a text file of commands to send via curl and then somehow have all of them run at once. It's been a long time since I dealt with UNIX commands, but can someone show me how to accomplish this please (assuming I have a file created called commands.txt)?

Editing this post to include an example of the file of commands I would like to execute in batch...

curl -XPUT 'http://localhost:9200/foo/property/1' -d '{"firstName":"Domino","lastName":"Derval"}'
curl -XPUT 'http://localhost:9200/foo/property/2' -d '{"firstName":"Elektra","lastName":"King"}'
curl -XPUT 'http://localhost:9200/foo/property/3' -d '{"firstName":"Fiona","lastName":"Volpe"}'
curl -XPUT 'http://localhost:9200/foo/property/4' -d '{"firstName":"Holly","lastName":"Goodhead"}'
curl -XPUT 'http://localhost:9200/foo/property/5' -d '{"firstName":"Honey","lastName":"Rider"}'
curl -XPUT 'http://localhost:9200/foo/property/6' -d '{"firstName":"Jill","lastName":"Masterton"}'
curl -XPUT 'http://localhost:9200/foo/property/7' -d '{"firstName":"Kissy","lastName":"Suzuki"}'
curl -XPUT 'http://localhost:9200/foo/property/8' -d '{"firstName":"Mary","lastName":"Goodnight"}'
curl -XPUT 'http://localhost:9200/foo/property/9' -d '{"firstName":"Miranda","lastName":"Frost"}'
curl -XPUT 'http://localhost:9200/foo/property/10' -d '{"firstName":"Molly","lastName":"Warmflash"}'
curl -XPUT 'http://localhost:9200/foo/property/11' -d '{"firstName":"Paula","lastName":"Caplan"}'
curl -XPUT 'http://localhost:9200/foo/property/12' -d '{"firstName":"Penelope","lastName":"Smallbone"}'
curl -XPUT 'http://localhost:9200/foo/property/13' -d '{"firstName":"Pussy","lastName":"Galore"}'
curl -XPUT 'http://localhost:9200/foo/property/14' -d '{"firstName":"Strawberry","lastName":"Fields"}'
curl -XPUT 'http://localhost:9200/foo/property/15' -d '{"firstName":"Sylvia","lastName":"Trench"}'
curl -XPUT 'http://localhost:9200/foo/property/16' -d '{"firstName":"Tatiana","lastName":"Romanova"}'
curl -XPUT 'http://localhost:9200/foo/property/17' -d '{"firstName":"Tilly","lastName":"Masterton"}'
curl -XPUT 'http://localhost:9200/foo/property/18' -d '{"firstName":"Vesper","lastName":"Lynd"}'
curl -XPUT 'http://localhost:9200/foo/property/19' -d '{"firstName":"Xenia","lastName":"Onatopp"}'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2025-01-02 02:23:14

创建脚本 download.sh

#!/bin/bash    
# put all your commands here
curl ...
.
.
.
curl ...

使 download.sh 可执行

$ chmod +x download.sh

运行 donwload.sh

$ ./download.sh

create a script download.sh

#!/bin/bash    
# put all your commands here
curl ...
.
.
.
curl ...

make download.sh executable

$ chmod +x download.sh

run donwload.sh

$ ./download.sh
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文