重试某个命令 2014/11/25 15153 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 }