summaryrefslogtreecommitdiffstats
path: root/waitfor
blob: 7077c670575fd86d459a9e785d635276806f8174 (plain)
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
#!/bin/bash
# wait for a string to appear at the end of file
# tridge@samba.org July 2008

[ $# -lt 3 ] && {
    cat <<EOF
Usage: waitfor FILE MESSAGE TIMEOUT
EOF
exit 1
}

file="$1"
msg="$2"
timeout="$3"

tmpfile=`mktemp`

cat <<EOF > $tmpfile
spawn tail -n 10000 -f $file
expect -timeout $timeout -re "$msg"
EOF

export LANG=C
expect $tmpfile
rm -f $tmpfile

if ! grep -E "$msg" $file > /dev/null; then
 echo "Failed to find \"$msg\" in $file"
 exit 1
fi
exit 0