bash - 并行运行多个 curl 命令

标签 bash shell curl

我有以下 shell 脚本。问题是我想并行/并发运行事务,而不是等待一个请求完成以转到下一个请求。例如,如果我发出 20 个请求,我希望它们同时执行。

for ((request=1;request<=20;request++))
do
    for ((x=1;x<=20;x++))
    do
        time curl -X POST --header "http://localhost:5000/example"
    done
done

有指导吗?

最佳答案

您可以使用带有 -P 选项的 xargs 并行运行任何命令:

seq 1 200 | xargs -n1 -P10  curl "http://localhost:5000/example"

这将运行 curl 命令 200 次,最多并行执行 10 个作业。

关于bash - 并行运行多个 curl 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46362284/

相关文章:

linux - Bash 使用变量从脚本运行脚本

php - 如何使用 PHP Gouttee 发送自定义 header

PHP:使用 POST 数据模拟 <form> 标记并重定向用户

linux - 将变量列表传递给简单的 bash 命令

regex - 读取命令的输出或从文件中读取

bash - 在 bash 管道中,将上一个命令的输出作为下一个命令的变量(例如 if 语句)

linux - 通过 omprog(syslog 模块)将命令行参数传递给 shell 脚本

linux - 将文件复制到备份目录保留文件夹结构

linux - 无需下载即可获取 Content-Disposition 文件名

bash - 如何使用 sed 将 LF 替换为空格,而不是 CRLF?