summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2008-07-29 15:36:35 +1000
committerAndrew Tridgell <tridge@samba.org>2008-07-29 15:36:35 +1000
commit346fd77a2acb9cb91540215e2137605cf084e2d2 (patch)
tree83cde8a055afdbc7f33894d06b699ee7970427b4
parent1c3d1ba3ae793cc328bd1885ec96ea5a3d18d123 (diff)
split out waitfor
-rwxr-xr-xautocluster13
-rwxr-xr-xbase/usr/bin/waitfor30
-rwxr-xr-xwaitfor30
3 files changed, 64 insertions, 9 deletions
diff --git a/autocluster b/autocluster
index 5d7a6df..4e114bc 100755
--- a/autocluster
+++ b/autocluster
@@ -255,18 +255,13 @@ EOF
sleep 2
# wait for the install to finish
- cat <<EOF > tmp/wait.exp
-spawn tail -f $KVMLOG/serial.$NAME
-expect -timeout 3600 "you may safely reboot your system"
-EOF
-
- expect tmp/wait.exp
- $VIRSH destroy $NAME
-
- if ! grep "you may safely reboot your system" $KVMLOG/serial.$NAME > /dev/null; then
+ if ! waitfor $KVMLOG/serial.$NAME "you may safely reboot your system" 3600; then
+ $VIRSH destroy $NAME
echo "Failed to create base image $DISK"
exit 1
fi
+
+ $VIRSH destroy $NAME
ls -l $DISK
cat <<EOF
diff --git a/base/usr/bin/waitfor b/base/usr/bin/waitfor
new file mode 100755
index 0000000..cb296d3
--- /dev/null
+++ b/base/usr/bin/waitfor
@@ -0,0 +1,30 @@
+#!/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 "$msg"
+EOF
+
+expect $tmpfile
+rm -f $tmpfile
+
+if ! grep "$msg" $file > /dev/null; then
+ echo "Failed to find \"$msg\" in $file"
+ exit 1
+fi
+exit 0
diff --git a/waitfor b/waitfor
new file mode 100755
index 0000000..cb296d3
--- /dev/null
+++ b/waitfor
@@ -0,0 +1,30 @@
+#!/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 "$msg"
+EOF
+
+expect $tmpfile
+rm -f $tmpfile
+
+if ! grep "$msg" $file > /dev/null; then
+ echo "Failed to find \"$msg\" in $file"
+ exit 1
+fi
+exit 0