每 5 秒运行一次 cURL 命令

问题描述 投票:0回答:2

这是我要运行的命令 -

curl --request POST --data-binary @payload.txt --header "carriots.apiKey:XXXXXXXXXXXXXXXXXXXX" --verbose http://api.carriots.com/streams

这基本上将数据流发送到服务器。

我想每 5 秒运行一次这个命令。我如何实现这一目标?

linux bash shell curl
2个回答
111
投票

您可以在 while 循环中运行。

while sleep 5; do cmd; done

编辑:

如果您不想使用

while..loop
。您可以使用watch命令。

watch -n 5 cmd

14
投票

完成相同任务的另一种简单方法是:

watch -n {{seconds}} {{your-command}}

例如,每 900 毫秒(请注意“your-command”周围的双引号):

watch -n 0.9 "{{your-command}}"
© www.soinside.com 2019 - 2024. All rights reserved.