I have quite a few scripts running on my home server and they love writing on disk. They love it so much that, after reboot, they don’t necessarily wait for mount points to appear - they just start writing. Unfortunately, such eagerness also means that my other scripts mounting ZFS might find directory already in use and give up.
What I needed was a way to check if mount point is already there before starting with write. The easiest approach for me was using mountpoint
command.
TEST_PATH=/test/directory
while(true); do # wait for mount point
mountpoint "$TEST_PATH" >/dev/null
if [[ $? != 0 ]]; then
sleep 1
continue
fi
break
done
Script fragment above will check if given directory has something mounted and, if not, wait for 1 more second. Once test succeeds, it will break out of the infinite loop and proceed with whatever follows.
Easy enough.