如何在bash中创建一个等待Web服务器响应的循环?
它应该打印一个"." 每10秒钟左右,等到服务器开始响应.
更新,此代码测试我是否从服务器得到了良好的响应.
if curl --output /dev/null --silent --head --fail "$url"; then echo "URL exists: $url" else echo "URL does not exist: $url" fi
Tho*_*sen 142
将问题与chepner的答案结合起来,这对我有用:
until $(curl --output /dev/null --silent --head --fail http://myhost:myport); do
printf '.'
sleep 5
done
Run Code Online (Sandbox Code Playgroud)
ill*_*nan 31
我想限制最大尝试次数.根据托马斯接受的答案,我做了这个:
attempt_counter=0
max_attempts=5
until $(curl --output /dev/null --silent --head --fail http://myhost:myport); do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi
printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 5
done
Run Code Online (Sandbox Code Playgroud)
twi*_*kes 23
海报询问了有关打印的具体问题.,但我认为大多数人来这里都是在寻找下面的解决方案,因为它是支持有限重试的单个命令。
curl --head -X GET --retry 5 --retry-connrefused --retry-delay 1 http://myhost:myport
Run Code Online (Sandbox Code Playgroud)
Bru*_*dge 11
httping对此很好.简单,干净,安静.
while ! httping -qc1 http://myhost:myport ; do sleep 1 ; done
Run Code Online (Sandbox Code Playgroud)
而/等等是个人的首选.
| 归档时间: |
|
| 查看次数: |
63552 次 |
| 最近记录: |