github.com/mackerelio/mackerel-agent-plugins@v0.89.3/tool/waituntil.bash (about) 1 #!/bin/bash 2 # usage: waituntil [-n count] command [arg ...] 3 4 usage() 5 { 6 echo "usage: $(basename $0) [-n count] command [arg ...]" >&2 7 exit 2 8 } 9 10 count=0 # unlimited 11 while getopts :n: OPT 12 do 13 case "$OPT" in 14 :) usage ;; 15 n) count="$OPTARG" ;; 16 \?) usage ;; 17 esac 18 done 19 shift $((OPTIND - 1)) 20 if (($# == 0)) 21 then 22 usage 23 fi 24 25 i=0 26 while (($count == 0 || $i < $count)) 27 do 28 if command "$@" 29 then 30 exit 0 31 fi 32 sleep 1 33 ((i++)) 34 done 35 exit 1