Writing Shell Scripts that Only Allow One Instance to Run
jfpossibilities.com·2d
🐚Shell Scripting
Preview
Report Post

by Jon Foster - 2023-06-19 Updated: 2025-07-21

As a UNIX admin it’s often required that certain scripts only allow a single simultogetherous instance to run. For me this most often happens with backup scripts. The duration of a single run of a script is tied to how much data you want to copy and how fast it can move. This varies from day to day and in many scenarios could take longer to run than the time window provided by the CRON schedule. In other words: a daily backup could take longer than a day. And starting a second backup while the first is still running compounds issues.

There may be any number of other reasons a script needs to be limited to a single running instance. So it is handy to have a mechanism that we can use in the limited facilities of BASH or other shells t…

Similar Posts

Loading similar posts...