Retry a Bash command with timeout

前端 未结 5 666
情歌与酒
情歌与酒 2020-12-28 12:51

How to retry a bash command until its status is ok or until a timeout is reached?

My best shot (I\'m looking for something simpler):

NEXT_WAIT_TIME=0         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-28 13:37

    You can simplify things a bit by putting command right in the test and doing increments a bit differently. Otherwise the script looks fine:

    NEXT_WAIT_TIME=0
    until [ $NEXT_WAIT_TIME -eq 5 ] || command; do
        sleep $(( NEXT_WAIT_TIME++ ))
    done
    [ $NEXT_WAIT_TIME -lt 5 ]
    

提交回复
热议问题