File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / testing / hosts / default / usr / local / bin / expect-file
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 09:46:48 2020 UTC (4 years, 10 months ago) by misho
Branches: strongswan, MAIN
CVS tags: v5_9_2p0, v5_8_4p7, HEAD
Strongswan

#!/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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>