Cleanup post-boot cluster configuration
[autocluster.git] / waitfor
1 #!/bin/bash
2 # wait for a string to appear at the end of file
3 # tridge@samba.org July 2008
4
5 [ $# -lt 3 ] && {
6     cat <<EOF
7 Usage: waitfor FILE MESSAGE TIMEOUT
8 EOF
9 exit 1
10 }
11
12 file="$1"
13 msg="$2"
14 timeout="$3"
15
16 tmpfile=`mktemp`
17
18 cat <<EOF > $tmpfile
19 spawn tail -n 10000 -f $file
20 expect -timeout $timeout -re "$msg"
21 EOF
22
23 export LANG=C
24 expect $tmpfile
25 rm -f $tmpfile
26
27 if ! grep -E "$msg" $file > /dev/null; then
28  echo "Failed to find \"$msg\" in $file"
29  exit 1
30 fi
31 exit 0