Generic cron script wrapper with lock file management and stale lock detection.
Prevents overlapping executions of cron jobs and handles stuck processes.
Follows Linux convention: place your actual scripts in /opt or /usr/local/bin, then use wrapper scripts in cron to call them. This wrapper avoids putting scripts directly in cron directories like /etc/cron.daily.
- Copy
cron-wrapperto a new name - Set
TARGET_SCRIPTto your script path - Configure environment variables as needed
chmod +xthe wrapper- Call from cron or run manually
TARGET_SCRIPT– Path to script to execute (required)STALE_LOCK_THRESHOLD_SECONDS– Lock timeout in seconds (default: 3600)
- Lock file with automatic stale detection
- Timestamp-based lock validation
- Clean exit handling
- Logging with timestamps
- Export of environment variables to target script