I have a script that writes to a file and then dumps that file to a database. I need this task to run as frequently as possible, but never run more than instance at the same time (or it'd be writing redundant stuff to the same file).
How I am currently doing it is in the shell script I am checking to see if a file exists, and if it does, I exit the script. At the end of each script it deletes the file.
This works 95% of the time. However, if the server is restarted (which happens semi-frequently), the file that was being written to will remain, and every time the script is called after that it will exit because the file already exists.
What would be a good way around this problem?