Skip to content

Instantly share code, notes, and snippets.

@StoneLabs
Created May 7, 2020 13:40
Show Gist options
  • Select an option

  • Save StoneLabs/df7be5d09fb1f0a56d641105b00b392f to your computer and use it in GitHub Desktop.

Select an option

Save StoneLabs/df7be5d09fb1f0a56d641105b00b392f to your computer and use it in GitHub Desktop.
Wait for file deletion or timeout (bash)
# 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
}
@alexandervlpl

Copy link
Copy Markdown

If you're on Linux, just do this:

timeout 5 inotifywait -e delete_self $file

@rmarkus

rmarkus commented Jan 26, 2025

Copy link
Copy Markdown

wait_file() works like a charm. thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment