Skip to content

Instantly share code, notes, and snippets.

@mattes
Last active December 24, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattes/6742398 to your computer and use it in GitHub Desktop.
Save mattes/6742398 to your computer and use it in GitHub Desktop.
pid-file.sh <pid-file> <appear|disappear> [wait sec]
#!/usr/bin/env bash
file=$1
to=$2
wait_seconds=$3 # optional
[[ $file == "" ]] && echo "No file given." && exit 1
[[ $wait_seconds == "" ]] && wait_seconds=10
[[ $to == "" ]] && echo "Wait for file to appear or disappear?" && exit 1
waited_seconds=0
while [[ (($to == "appear" && ! -e $file) || ($to == "disappear" && -e $file)) && $waited_seconds -lt $wait_seconds ]]; do
printf "."
sleep 1
waited_seconds=$[waited_seconds + 1]
done
if [[ $waited_seconds -ge $wait_seconds ]]; then
printf " (timeout after $waited_seconds seconds)"
fi
if [[ ($to == "appear" && ! -e $file) || ($to == "disappear" && -e $file) ]]; then
printf " FAILED\n"
exit 1
else
printf " OK\n"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment