Last active
March 31, 2023 23:36
-
-
Save steezeburger/ec4fccf9038d352ab71002a90cfad49d to your computer and use it in GitHub Desktop.
Similar to the popular wait-for-it.sh that waits for a network connection, this bash script waits for a file to exist. It does not have the same api as wait-for-it.sh, but could be extended easily enough to be the same.
This file contains 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/bash | |
# Usage: ./wait-for-file.sh /path/to/your/file | |
FILE_PATH="$1" | |
TIMEOUT=30 | |
SLEEP_INTERVAL=1 | |
ELAPSED=0 | |
if [ -z "$FILE_PATH" ]; then | |
echo "Usage: $0 /path/to/your/file" | |
exit 1 | |
fi | |
echo "Waiting for file: $FILE_PATH" | |
while [ ! -f "$FILE_PATH" ]; do | |
sleep $SLEEP_INTERVAL | |
ELAPSED=$((ELAPSED + SLEEP_INTERVAL)) | |
if [ $ELAPSED -ge $TIMEOUT ]; then | |
echo "Timeout reached, file not found." | |
exit 1 | |
fi | |
done | |
echo "File is now available: $FILE_PATH" | |
# Continue with your script here... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment