Works with the AI Agents you already use
Cron-Safe Shell Scripts: Locking, Logging, Alerts
by Saizul Amin
Validate cron schedules, fix environment-related failures, and add reliable locking to scheduled scripts.
$4
Cron-Safe Shell Scripts: Locking, Logging, Alerts
Example session with this skill installed
Run the Cron-Safe Shell Scripts skill on my project and give me a prioritised list of what to fix, with exact changes.
- Read your context and instructions
- Compiled the cron-safe shell scripts
Here is what the Cron-Safe Shell Scripts: Locking, Logging, Alerts skill produced.
Demo: real, unedited output of the skill's bundled script on a sample input from its test suite.
Output
environment: MAILTO=, PATH=$PATH:/usr/local/bin
line 4: * * * * * /home/app/bin/poll.sh
when: every minute
next: 2026-02-27 10:01, 2026-02-27 10:02, 2026-02-27 10:03
MEDIUM CR004: runs every 1 min without a lock: a slow run overlaps the next one
fix: wrap it: flock -n /tmp/job.lock cmd (Linux) or use the cron-wrapper.sh asset
LOW CR003: MAILTO is empty, so output and errors are silently discarded
fix: redirect to a log file (>>file 2>&1) or set MAILTO to a monitored address
line 5: */5 * * * * cd /srv/app; php artisan schedule:run >/dev/null 2>&1
when: every 5 minutes
next: 2026-02-27 10:05, 2026-02-27 10:10, 2026-02-27 10:15
MEDIUM CR003: all output including errors goes to /dev/null: failures are invisible
fix: log instead: >>job.log 2>&1, or 2>&1 | logger -t job, or the cron-wrapper.sh asset
MEDIUM CR004: runs every 5 min without a lock: a slow run overlaps the next one
fix: wrap it: flock -n /tmp/job.lock cmd (Linux) or use the cron-wrapper.sh asset
MEDIUM CR009: 'cd dir; cmd' runs cmd in the home directory when cd fails
fix: use cd /abs/dir && cmd
line 6: 0 3 * * * /usr/bin/tar czf /backup/site-$(date +%F).tgz /var/www
when: at 03:00
next: 2026-02-28 03:00, 2026-03-01 03:00, 2026-03-02 03:00
HIGH CR002: unescaped % in the command: cron turns it into a newline and passes the rest as stdin
fix: escape it as \% (date +\%F) or move the command into a script
LOW CR003: MAILTO is empty, so output and errors are silently discarded
fix: redirect to a log file (>>file 2>&1) or set MAILTO to a monitored address
line 7: 30 2 30 2 * /usr/local/bin/never.sh
when: at 02:30 on day-of-month 30 in month 2
HIGH CR012: '30 2 30 2 *' never runs (no matching date in the next 5 years)
fix: check day-of-month against the month (e.g. 30 2 never exists)
LOW CR003: MAILTO is empty, so output and errors are silently discarded
fix: redirect to a log file (>>file 2>&1) or set MAILTO to a monitored address
line 8: 15 4 1 * 1 /usr/local/bin/report.sh >> report.log 2>&1
when: at 04:15 on day-of-month 1 or day-of-week Mon
next: 2026-03-01 04:15, 2026-03-02 04:15, 2026-03-09 04:15
INFO CR013: both day-of-month and day-of-week are set: cron runs when EITHER matches
fix: to run on e.g. the first Monday, use '* * 1-7 * *' with a date +%u test in the command (escape % as \%)
line 9: 0 * * * * ./scripts/cleanup.sh
when: at minute 0 of every hour
next: 2026-02-27 11:00, 2026-02-27 12:00, 2026-02-27 13:00
MEDIUM CR005: './scripts/cleanup.sh' is relative: cron starts in the home directory, not your project
fix: use an absolute path (/home/app/bin/job.sh) or cd /abs/dir && ./job.sh
LOW CR003: MAILTO is empty, so output and errors are silently discarded
fix: redirect to a log file (>>file 2>&1) or set MAILTO to a monitored address
line 10: 0 1 * * * sudo /usr/sbin/logrotate /etc/logrotate.conf
when: at 01:00
next: 2026-02-28 01:00, 2026-03-01 01:00, 2026-03-02 01:00
MEDIUM CR007: sudo in cron has no terminal for a password and hides which user really runs the job
fix: put the job in root's crontab (sudo crontab -e) or /etc/cron.d with a user field
LOW CR003: MAILTO is empty, so output and errors are silently discarded
fix: redirect to a log file (>>file 2>&1) or set MAILTO to a monitored address
line 11: @reboot [[ -d /mnt/data ]] && /usr/local/bin/start.sh
when: once when the cron daemon starts
MEDIUM CR006: bash syntax in a cron command, but cron runs commands with /bin/sh
fix: set SHELL=/bin/bash in the crontab, or move the command into a bash script
LOW CR003: MAILTO is empty, so output and errors are silently discarded
fix: redirect to a log file (>>file 2>&1) or set MAILTO to a monitored address
INFO CR010: @reboot runs when cron starts, possibly before network and mounts are ready
fix: add a wait for the dependency, or use a systemd service with After=network-online.target
line 12: 61 * * * * /bin/true
HIGH CR001: invalid schedule: minute: 61 is outside 0-59
fix: see `man 5 crontab`
line 13: 0 0 * * mon-fri /usr/local/bin/weekday.sh >> weekday.log 2>&1
when: at 00:00 on day-of-week mon-fri
next: 2026-03-02 00:00, 2026-03-03 00:00, 2026-03-04 00:00
line 14: 0 0 * * mon-fri /usr/local/bin/weekday.sh >> weekday.log 2>&1
when: at 00:00 on day-of-week mon-fri
next: 2026-03-02 00:00, 20
What you do next
- Fix the highest-severity items first.
- Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
- Keep the skill installed and re-run it whenever the project changes.
Connects securely to your tools. The creator never sees your data.
About this skill
Cron jobs often fail silently because they run in a stripped-down environment different from your terminal. This skill provides a deterministic checker and a POSIX-compliant wrapper to identify and fix common cron pitfalls like missing paths, unescaped percent signs, and overlapping runs.
What it does
- Validate schedules: Parse cron expressions to provide plain-English descriptions and future run times.
- Audit configurations: Detect unescaped
%characters, bash-specific syntax in/bin/sh, and relative file paths. - Safety checks: Identify overlapping jobs lacking locks and jobs that discard error output via
>/dev/null 2>&1. - Systemd migration: Generate equivalent systemd timers for jobs requiring resource limits or dependency management.
- Runtime wrapping: Provide a script to handle locking, timeouts, and timestamped logging for any cron task.
How it works
- Extract crontab: Export the current user's crontab or system-level
/etc/cron.dfiles to a local file. - Run audit: Execute the
cron_check.pyscript against the file to detect issues across 15+ error categories. - Apply fixes: Update the crontab based on findings, such as escaping characters or adding
&&aftercdcommands. - Deploy wrapper: Use
cron-wrapper.shfor frequent jobs to prevent race conditions and capture logs.
Frameworks & tools
Uses a Python 3.8+ standard library script for analysis. Includes a POSIX-compliant shell wrapper compatible with Linux flock and macOS mkdir lock fallbacks. Works with standard crontab formats and systemd.
Why this beats prompting it yourself
Standard LLMs often overlook that % is a newline trigger in cron or that cron uses /bin/sh instead of your default shell. This skill uses a deterministic rule engine to catch specific POSIX cron behaviors that general prompting misses.
Use cases
- Debugging a script that works manually but fails when scheduled.
- Preventing server resource exhaustion caused by overlapping cron processes.
- Translating complex cron expressions into human-readable schedules for audits.
- Hardening production crontabs against environment variable and pathing errors.
Known limitations
Does not lint internal shell script logic like quoting or rm -rf risks. Checker ignores cloud-specific schedulers like Kubernetes CronJobs where environment handling differs.
Open source: saizul/bash-shell-skills on GitHub (MIT licence, by Saizul Amin).
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for LLM Ops.
Does not lint internal script logic like syntax errors inside the target script. Optimized for POSIX cron and systemd, not cloud-native schedulers.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 2 days ago
- Software
Python 3.8+