Created
May 7, 2020 13:40
-
-
Save StoneLabs/df7be5d09fb1f0a56d641105b00b392f to your computer and use it in GitHub Desktop.
Wait for file deletion or timeout (bash)
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
# Function | |
wait_file() { | |
local file="$1"; shift | |
local wait_seconds="${1:-10}"; shift # 10 seconds as default timeout | |
until test $((wait_seconds--)) -eq 0 -o ! -f "$file" ; do sleep 1; done | |
((++wait_seconds)) | |
} | |
# Example call | |
wait_file /tmp/program.lck 20\ || { | |
echo "Lock timeout :(" | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're on Linux, just do this:
timeout 5 inotifywait -e delete_self $file