重试某个命令

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

retry() {
    if [ $# != 2 -a $# != 3 ]; then
        echo "Useage: $0 cmd try-times [delay-seconds=60]" >&2
        return 255
    fi
    cmd=$1
    n=$2
    delay=${3:-60}
    ret=255
    for i in `seq 1 $n`; do
        eval $cmd
        ret=$?
        test $ret -eq 0 && return 0
        sleep $delay
    done
    return $ret
}