flock

Manage file locks to prevent concurrent execution of commands

brewmacoslinux
Try with needOr install directly
Source

About

Lock file during command

Commands

flock

Examples

Lock a file and run a command exclusively$ flock /tmp/my.lock command_to_run
Create a lock file and execute a script with timeout$ flock -w 10 /var/lock/backup.lock ./backup.sh
Run multiple commands with shared lock to prevent parallel execution$ flock /tmp/db.lock bash -c 'command1 && command2'