You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何延迟curl请求?添加sleep后未达预期效果求助

解决curl请求添加sleep延迟无效的问题

你的命令里错误地将'; sleep 5m'当作了curl的请求参数,而非独立执行的shell命令,所以sleep根本没被触发,反而会被curl当作目标URL处理,这就是延迟不生效的原因。以下是正确的实现方式:

方案1:每个curl请求后固定延迟5分钟

将curl和sleep打包成一个shell命令,通过sh -c让xargs执行:

xargs -I{} sh -c 'curl --location --request POST "https://g.com" \
--header "Authorization: Bearer cc" \
--header "Content-Type: application/json" \
--data-raw "{
    \"c_ids\": [
        \"{}\"
    ]
}"; sleep 5m' < ~/recent.txt

方案2:更安全的参数传递(避免转义问题)

如果你的recent.txt里包含特殊字符,建议用参数传递的方式,减少转义出错的概率:

xargs -I{} sh -c 'curl --location --request POST "https://g.com" \
--header "Authorization: Bearer cc" \
--header "Content-Type: application/json" \
--data-raw "{
    \"c_ids\": [
        \"$1\"
    ]
}"; sleep 5m' sh {} < ~/recent.txt

方案3:控制并发数+延迟

如果需要同时执行少量请求(比如最多2个并发),同时保持每个请求后的延迟,可以加上-P参数:

xargs -P 2 -I{} sh -c 'curl --location --request POST "https://g.com" \
--header "Authorization: Bearer cc" \
--header "Content-Type: application/json" \
--data-raw "{
    \"c_ids\": [
        \"$1\"
    ]
}"; sleep 5m' sh {} < ~/recent.txt

内容的提问来源于stack exchange,提问作者lg543

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 18:01:25