I am setting up my first cron on a Ubuntu Desktop system. I was curious to know if there is a way to lock a folder before a cron is ran and how to set it up? I am following this article. I am just trying to make sure I don't damage any files when moving them from and to the cron folder because it is on a shared network.
A simple script with locking and a delay before accessing files:
The main features are:
You should be able to modify the
Ubuntu also has
This isn't ideal, but effective. You have a separate, 'feeder' directory that you copy new files into, when copying them onto the network. Your cron script can then perform an /ls of /var/feeder, then lsof each file in that directory looking for any open file handles. Files that aren't in use are then moved into the main shared directory, files that are open (presumably you're copying them or some such) are left in the feeder. Ensure the main /shared directory isn't writable except by your script, and you should be good.