I have a cronjob for rsync which runs every 2 minutes, but sometimes takes longer then 2 minutes. For that I wrote a simple locking system which checks, if file not found writes lockfile, takes action and deletes that lockfile.
Now if the script crashes or is killed for some reason that lockfile will linger on and cause problems.
What would be a good way of making sure the cron task is run again at some point? I have thought of checking the age of the lockfile and deleting it if older then a certain period, but there ought to be better more elegant solutions for this I'd think..
I now have implemented flock. I was a bit confused as to why the file always seems to exist, but I found this page that explains how it works, by storing the pid in the file information: