sequence is a locking unique sequence generator.
The current sequence number is stored in a file only to be incremented when locked. This script should be fairly robust, avoiding any loss of the sequence number, even during program interruptions. The sequence number is backed up in another file before being overwritten (incremented).
This script also ensures that any number never gets used twice by verifying that the sequence is indeed incremented in the filesystem (and unlocked) before ever returning a newly incremented number. The only failures should be skipped numbers, but never duplicate ones.
Use: sequence next DB > the next number in the sequence
DB is a file to keep track of the current sequence. Be aware that the file DB.last will be used to backup the sequence during incrementation. Lock files such as DB.lock will also be used.
To start a new sequence:
Use: sequence init DB