3 ms·
Or just have your script make a lock file somewhere on a persistent file system and exit if it exists.
by gleventhal 5y ago
Or just have your script make a lock file somewhere on a persistent file system and exit if it exists.
- tenebrisalietum 5y agoThat solves reentrancy, when you don't want two copies of a script active at once, but what if you only want to run the lines in a script that weren't already run on last invocation?
- ruined 5y agowrite the actual script in a heredoc, and wrap it in a script that pipes it line-by-line into a shell and tees to the lockfile. then, if the script stops, you have a journal of what's executed so far, and the next execution can just skip everything duplicated in the logckfile. totally foolproof except for the race condition between when your script crashes and you hit up-arrow then enter, someone else with your user account might change it maliciously.
- charcircuit 5y agoand what do you do if the script stops for some reason? It can be difficult to know what you need to do properly get back into a valid state. Just deleting the lock can cause problems.