File: wait_on_condition

package info (click to toggle)
python-irodsclient 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,352 kB
  • sloc: python: 16,650; xml: 525; sh: 104; awk: 5; sql: 3; makefile: 3
file content (34 lines) | stat: -rwxr-xr-x 752 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash

# wait for a program to run with 0 return status

interval=3; ntimes=20; verbose=""

usage() {
  echo "$0 [options] <command args...>"
  printf "\t options are: -i <sleep interval_secs> (default %d)\n" $interval
  printf "\t              -n <integer_number_of_tries> (default %d)\n" $ntimes
  printf "\t              -v : for verbose reporting\n"
  exit 1
} >&2

while [[ "$1" = -* ]] ; do
    case $1 in
	-i) shift; interval=$1; shift ;;
	-n) shift; ntimes=$1; shift ;;
	-v) verbose=1 ; shift;;
	 *) usage;;
    esac
done
[ $# -eq 0 ] && usage

n=1
while : ; do
	eval "$@"
	STATUS=$?
	[ -n "$verbose" ] && echo "$n:" 'STATUS =' $STATUS `date`
	[ $((++n)) -gt $ntimes -o $STATUS -eq 0 ] && break
        sleep $interval
done

exit $STATUS