equal
deleted
inserted
replaced
|
1 #!/bin/bash |
|
2 # |
|
3 # wait up to TIMEOUT seconds until a WAIT_ON_FILE is created. |
|
4 # |
|
5 # In addition, this script can create CREATE_FILE once it is ready to wait. |
|
6 |
|
7 if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
|
8 echo $# |
|
9 echo "USAGE: $0 TIMEOUT WAIT_ON_FILE [CREATE_FILE]" |
|
10 fi |
|
11 |
|
12 timer="$1" |
|
13 wait_on="$2" |
|
14 create="" |
|
15 if [ $# -eq 3 ]; then |
|
16 create="$3" |
|
17 fi |
|
18 |
|
19 if [ -n "$create" ]; |
|
20 then |
|
21 touch "$create" |
|
22 create="" |
|
23 fi |
|
24 while [ "$timer" -gt 0 ] && [ ! -f "$wait_on" ]; |
|
25 do |
|
26 timer=$(( timer - 1)) |
|
27 sleep 0.01 |
|
28 done |
|
29 if [ "$timer" -le 0 ]; then |
|
30 echo "file not created after $1 seconds: $wait_on" >&2 |
|
31 exit 1 |
|
32 fi |