Created
February 22, 2018 07:17
-
-
Save efrecon/a93124bc1ac9968420cd4b17b08ef521 to your computer and use it in GitHub Desktop.
Wait for a number of files to be present (including 0, the use case!) and start a command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Number of files to wait for, 0 is usually what you want | |
TARGET=$1 | |
# Pattern to match path | |
PATTERN=$2 | |
# Command to execute once target has been reached | |
COMMAND=$3 | |
while true; do | |
NFILES=$(ls -1 ${PATTERN}|wc -l) | |
WHEN=$(date +'%Y%m%d %H:%M:%S') | |
echo "[${WHEN}] $NFILES file(s) matching $PATTERN" | |
if [ "$NFILES" -eq "$TARGET" ]; then | |
exec $3 | |
fi | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment