Last active
December 24, 2015 04:09
-
-
Save mattes/6742398 to your computer and use it in GitHub Desktop.
pid-file.sh <pid-file> <appear|disappear> [wait sec]
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
#!/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