cronlock: stop overlapping cron jobs with flock (plus timeout and failure webhooks)
Description and use
cronlock simplifies cron job management by ensuring single instances, optional timeouts, logging, and failure notifications, reducing script complexity.
Problem
Cron jobs can overlap if a job runs longer than its schedule, causing resource contention, corrupted data, or runaway processes.
Outcome
cronlock simplifies cron job management by ensuring single instances, optional timeouts, logging, and failure notifications, reducing script complexity and errors.
Workflow
- 1. Install cronlock by copying it to a directory in $PATH and making it executable.
- 2. Use cronlock with desired options: --name, --timeout, --log, --notify, followed by the command to run.
- 3. cronlock acquires an advisory lock with flock -n; if lock is held, it exits 0 and skips execution.
- 4. If a timeout is set, cronlock runs the command via timeout, enforcing the limit.
- 5. cronlock logs start and end timestamps and streams command output to the specified log file.
- 6. If the command exits non‑zero, cronlock POSTs a JSON payload to the provided webhook URL.
- 7. The script exits with the wrapped command’s exit code (or 0 if skipped).
Evidence
Cron schedules tasks at fixed intervals. If a job runs longer than its interval, the next invocation starts before the previous one finishes.
cronlock ties all of those primitives together in a single, tiny wrapper.
cronlock [--name NAME] [--timeout SECONDS] [--log FILE] [--notify URL] -- COMMAND [ARGS...]
If another backup is still running when the next cron tick fires, cronlock simply exits 0 without starting a second copy.
- Record date: 2026-10-14T19:56:05.197Z