Just wanna add to what @sjoerdhuininga said. That's absolutely the technique to go about it, provided your use-case can afford abrupt halting of the script and next run can cleanly continue.
I do wanna help you with an edge case you will quickly encounter.
lockfile here is simply a file created anywhere on disk (it could be empty), but let's add timestamp as content to this file. So, if your script fails in between, before it could delete this file at the end of execution, your script will never continue again cuz lockfile exists. Here now you can check the contents, get the timestamp, compare it with current timestamp and see if its more than X minutes (x minutes being the max time it should have taken to run), update the lockfile and just let it run.
Just wanna add to what @sjoerdhuininga said. That's absolutely the technique to go about it, provided your use-case can afford abrupt halting of the script and next run can cleanly continue.
I do wanna help you with an edge case you will quickly encounter.
lockfile here is simply a file created anywhere on disk (it could be empty), but let's add timestamp as content to this file. So, if your script fails in between, before it could delete this file at the end of execution, your script will never continue again cuz lockfile exists. Here now you can check the contents, get the timestamp, compare it with current timestamp and see if its more than X minutes (x minutes being the max time it should have taken to run), update the lockfile and just let it run.
hope that made sense.