#!/bin/sh
#
# Usage: after file1 [ file 2 ... ] - command [ arguments ]
# Waits for file1 (and file2 ...) to appear in current directory.
# Then runs command (with arguments).

WAITFOR=""
while [ "$1" != "-" ]; do
  WAITFOR="$WAITFOR $1"
  shift
done
shift

check_out() {
  for F in $*; do
    test -f $F || echo -n "$F "
  done
}

until [ -z "$WAITFOR" ]; do
  WAITFOR="`check_out $WAITFOR`"
  sleep 30
done

"$@"
