From: Reto Buerki Date: Thu, 24 Jan 2013 17:26:34 +0000 (+0100) Subject: Add expect-file guest image script X-Git-Tag: 5.0.3rc1~39^2~15 X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=commitdiff_plain;h=7b702150a091605dc3473f9d36ef05a22e6fcde7 Add expect-file guest image script This script can be used in pretest.dat files to wait until a given file appears. --- diff --git a/testing/hosts/default/usr/local/bin/expect-file b/testing/hosts/default/usr/local/bin/expect-file new file mode 100755 index 0000000..6921b66 --- /dev/null +++ b/testing/hosts/default/usr/local/bin/expect-file @@ -0,0 +1,29 @@ +#!/bin/bash +# +# Wait until a given file appears +# +# Params: +# $1 - filename +# $2 - maximum time to wait in seconds, default is 5 seconds + +if [[ $# -lt 1 || $# -gt 2 ]] +then + echo "invalid arguments" + exit 1 +fi + +secs=$2 +[ ! $secs ] && secs=5 + +let steps=$secs*10 +for i in `seq 1 $steps` +do + # -f does not work for special files (e.g. UNIX domain sockets), use ls + # instead + ls $1 >/dev/null 2>&1 + [ $? -eq 0 ] && exit 0 + sleep 0.1 +done + +echo "File '$1' not available after $secs second(s)" +exit 1