I need to remove the contents of a directory D based on the below condition
- Get the used space of directory D.
- If the used space is above the threshold, then remove the contents of directory based on last modified time (using find mtime)
Have already written a shell script for it (clearSpace.sh), but the problem is that the script can be called by multiple processes simultaneously.
I want the steps 1 & 2 to be atomic so that I can get consistent results.
Is there a way where I first get a "lock" on directory D and execute clearSpace.sh and then give the lock? Permission based locking is not an option