LinuxCommandLibrary

lckdo

runs commands with file locking

TLDR

Run with lock

$ lckdo [/var/lock/mylock] [command]
copy
Wait for lock
$ lckdo -W [lockfile] [command]
copy
Fail if locked
$ lckdo -n [lockfile] [command]
copy
With timeout
$ lckdo -w [10] [lockfile] [command]
copy

SYNOPSIS

lckdo [options] lockfile command

DESCRIPTION

lckdo executes a command while holding an exclusive file lock, ensuring that only one instance of the command runs at a time. This is particularly valuable for cron jobs and scheduled tasks where overlapping executions could cause data corruption or resource contention.
The tool acquires an exclusive lock on the specified lock file before running the command, and releases it when the command completes. By default it waits for the lock to become available, but you can use -n to fail immediately if the lock is held, or -w to set a timeout. Note that lckdo is deprecated in favor of `flock`, which provides the same functionality and is available as part of the standard util-linux package.

PARAMETERS

LOCKFILE

Lock file path.
COMMAND
Command to execute.
-n
Non-blocking (fail if locked).
-W
Wait forever for lock.
-w SECONDS
Wait timeout.
--help
Display help information.

CAVEATS

Deprecated in favor of flock. Part of moreutils. Lock file must be writable.

HISTORY

lckdo was part of moreutils for running commands under file locks, now replaced by flock.

SEE ALSO

flock(1), lockfile(1), chronic(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community