每5秒运行一次cURL命令

Arc*_*ora 14 linux curl libcurl

这是我要运行的命令 -

curl --request POST --data-binary @payload.txt --header "carriots.apiKey:XXXXXXXXXXXXXXXXXXXX" --verbose http://api.carriots.com/streams
Run Code Online (Sandbox Code Playgroud)

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

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

Jay*_*hoi 32

你可以在while循环中运行.

while sleep 5; do cmd; done
Run Code Online (Sandbox Code Playgroud)

编辑:

如果你不想使用while..loop.你可以使用watch命令.

watch -n 5 cmd
Run Code Online (Sandbox Code Playgroud)

  • 此外,如果与“--raw”一起使用以查看响应,还应使用标志“-s”来消除冗长。`watch -n 5 "curl --raw some.url -s"` (5认同)

Ant*_*cca 13

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

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

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

watch -n 0.9 "curl 'https://public-cloud.abstratium.dev/user/site'"
Run Code Online (Sandbox Code Playgroud)