[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M735BNHH6Y46DMVMD2EF3F3Y":3,"skill-same:01M735BNHH6Y46DMVMD2EF3F3Y":92},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":35,"commitSha":36,"skillDirectory":37,"forksCount":38,"repositoryHtmlUrl":39,"repositoryHomepageUrl":6,"ownerHtmlUrl":40,"ownerBlogUrl":41,"ownerDescription":42,"updatedAt":43,"install":44,"resources":57},"01M735BNHH6Y46DMVMD2EF3F3Y","cron-scheduling",null,"Schedule and manage recurring tasks with cron and systemd timers. Use when setting up cron jobs, writing systemd timer units, handling timezone-aware scheduling, monitoring failed jobs, implementing retry patterns, or debugging why a scheduled task didn't run.","antgroup\u002FAgent3Sigma-Canary","antgroup","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F37703784?v=4","01M7358T7C4N25D7PHG9RC6RV4","Ant Group","01M7358T7YBHP46FWXD1TXYJVV",41,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: cron-scheduling\ndescription: Schedule and manage recurring tasks with cron and systemd timers. Use when setting up cron jobs, writing systemd timer units, handling timezone-aware scheduling, monitoring failed jobs, implementing retry patterns, or debugging why a scheduled task didn't run.\nmetadata: {\"clawdbot\":{\"emoji\":\"⏰\",\"requires\":{\"anyBins\":[\"crontab\",\"systemctl\",\"at\"]},\"os\":[\"linux\",\"darwin\"]}}\n---\n\n# Cron & Scheduling\n\nSchedule and manage recurring tasks. Covers cron syntax, crontab management, systemd timers, one-off scheduling, timezone handling, monitoring, and common failure patterns.\n\n## When to Use\n\n- Running scripts on a schedule (backups, reports, cleanup)\n- Setting up systemd timers (modern cron alternative)\n- Debugging why a scheduled job didn't run\n- Handling timezones in scheduled tasks\n- Monitoring and alerting on job failures\n- Running one-off delayed commands\n\n## Cron Syntax\n\n### The five fields\n\n```\n┌───────── minute (0-59)\n│ ┌─────── hour (0-23)\n│ │ ┌───── day of month (1-31)\n│ │ │ ┌─── month (1-12 or JAN-DEC)\n│ │ │ │ ┌─ day of week (0-7, 0 and 7 = Sunday, or SUN-SAT)\n│ │ │ │ │\n* * * * * command\n```\n\n### Common schedules\n\n```bash\n# Every minute\n* * * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every 5 minutes\n*\u002F5 * * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every hour at :00\n0 * * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every day at 2:30 AM\n30 2 * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every Monday at 9:00 AM\n0 9 * * 1 \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every weekday at 8:00 AM\n0 8 * * 1-5 \u002Fpath\u002Fto\u002Fscript.sh\n\n# First day of every month at midnight\n0 0 1 * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every 15 minutes during business hours (Mon-Fri 9-17)\n*\u002F15 9-17 * * 1-5 \u002Fpath\u002Fto\u002Fscript.sh\n\n# Twice a day (9 AM and 5 PM)\n0 9,17 * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every quarter (Jan, Apr, Jul, Oct) on the 1st at midnight\n0 0 1 1,4,7,10 * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every Sunday at 3 AM\n0 3 * * 0 \u002Fpath\u002Fto\u002Fscript.sh\n```\n\n### Special strings (shorthand)\n\n```bash\n@reboot    \u002Fpath\u002Fto\u002Fscript.sh   # Run once at startup\n@yearly    \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 1 1 *\n@monthly   \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 1 * *\n@weekly    \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 * * 0\n@daily     \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 * * *\n@hourly    \u002Fpath\u002Fto\u002Fscript.sh   # 0 * * * *\n```\n\n## Crontab Management\n\n```bash\n# Edit current user's crontab\ncrontab -e\n\n# List current crontab\ncrontab -l\n\n# Edit another user's crontab (root)\nsudo crontab -u www-data -e\n\n# Remove all cron jobs (be careful!)\ncrontab -r\n\n# Install crontab from file\ncrontab mycrontab.txt\n\n# Backup crontab\ncrontab -l > crontab-backup-$(date +%Y%m%d).txt\n```\n\n### Crontab best practices\n\n```bash\n# Set PATH explicitly (cron has minimal PATH)\nPATH=\u002Fusr\u002Flocal\u002Fbin:\u002Fusr\u002Fbin:\u002Fbin\n\n# Set MAILTO for error notifications\nMAILTO=admin@example.com\n\n# Set shell explicitly\nSHELL=\u002Fbin\u002Fbash\n\n# Full crontab example\nPATH=\u002Fusr\u002Flocal\u002Fbin:\u002Fusr\u002Fbin:\u002Fbin\nMAILTO=admin@example.com\nSHELL=\u002Fbin\u002Fbash\n\n# Backups\n0 2 * * * \u002Fopt\u002Fscripts\u002Fbackup.sh >> \u002Fvar\u002Flog\u002Fbackup.log 2>&1\n\n# Cleanup old logs\n0 3 * * 0 find \u002Fvar\u002Flog\u002Fmyapp -name \"*.log\" -mtime +30 -delete\n\n# Health check\n*\u002F5 * * * * \u002Fopt\u002Fscripts\u002Fhealthcheck.sh || \u002Fopt\u002Fscripts\u002Falert.sh \"Health check failed\"\n```\n\n## Systemd Timers\n\n### Create a timer (modern cron replacement)\n\n```ini\n# \u002Fetc\u002Fsystemd\u002Fsystem\u002Fbackup.service\n[Unit]\nDescription=Daily backup\n\n[Service]\nType=oneshot\nExecStart=\u002Fopt\u002Fscripts\u002Fbackup.sh\nUser=backup\nStandardOutput=journal\nStandardError=journal\n```\n\n```ini\n# \u002Fetc\u002Fsystemd\u002Fsystem\u002Fbackup.timer\n[Unit]\nDescription=Run backup daily at 2 AM\n\n[Timer]\nOnCalendar=*-*-* 02:00:00\nPersistent=true\nRandomizedDelaySec=300\n\n[Install]\nWantedBy=timers.target\n```\n\n```bash\n# Enable and start the timer\nsudo systemctl daemon-reload\nsudo systemctl enable --now backup.timer\n\n# Check timer status\nsystemctl list-timers\nsystemctl list-timers --all\n\n# Check last run\nsystemctl status backup.service\njournalctl -u backup.service --since today\n\n# Run manually (for testing)\nsudo systemctl start backup.service\n\n# Disable timer\nsudo systemctl disable --now backup.timer\n```\n\n### OnCalendar syntax\n\n```ini\n# Systemd calendar expressions\n\n# Daily at midnight\nOnCalendar=daily\n# or: OnCalendar=*-*-* 00:00:00\n\n# Every Monday at 9 AM\nOnCalendar=Mon *-*-* 09:00:00\n\n# Every 15 minutes\nOnCalendar=*:0\u002F15\n\n# Weekdays at 8 AM\nOnCalendar=Mon..Fri *-*-* 08:00:00\n\n# First of every month\nOnCalendar=*-*-01 00:00:00\n\n# Every 6 hours\nOnCalendar=0\u002F6:00:00\n\n# Specific dates\nOnCalendar=2026-02-03 12:00:00\n\n# Test calendar expressions\nsystemd-analyze calendar \"Mon *-*-* 09:00:00\"\nsystemd-analyze calendar \"*:0\u002F15\"\nsystemd-analyze calendar --iterations=5 \"Mon..Fri *-*-* 08:00:00\"\n```\n\n### Advantages over cron\n\n```\nSystemd timers vs cron:\n+ Logs in journald (journalctl -u service-name)\n+ Persistent: catches up on missed runs after reboot\n+ RandomizedDelaySec: prevents thundering herd\n+ Dependencies: can depend on network, mounts, etc.\n+ Resource limits: CPUQuota, MemoryMax, etc.\n+ No lost-email problem (MAILTO often misconfigured)\n- More files to create (service + timer)\n- More verbose configuration\n```\n\n## One-Off Scheduling\n\n### at (run once at a specific time)\n\n```bash\n# Schedule a command\necho \"\u002Fopt\u002Fscripts\u002Fdeploy.sh\" | at 2:00 AM tomorrow\necho \"reboot\" | at now + 30 minutes\necho \"\u002Fopt\u002Fscripts\u002Freport.sh\" | at 5:00 PM Friday\n\n# Interactive (type commands, Ctrl+D to finish)\nat 10:00 AM\n> \u002Fopt\u002Fscripts\u002Ftask.sh\n> echo \"Done\" | mail -s \"Task complete\" admin@example.com\n> \u003CCtrl+D>\n\n# List pending jobs\natq\n\n# View job details\nat -c \u003Cjob-number>\n\n# Remove a job\natrm \u003Cjob-number>\n```\n\n### sleep-based (simplest)\n\n```bash\n# Run something after a delay\n(sleep 3600 && \u002Fopt\u002Fscripts\u002Ftask.sh) &\n\n# With nohup (survives logout)\nnohup bash -c \"sleep 7200 && \u002Fopt\u002Fscripts\u002Ftask.sh\" &\n```\n\n## Timezone Handling\n\n```bash\n# Cron runs in the system timezone by default\n# Check system timezone\ntimedatectl\ndate +%Z\n\n# Set timezone for a specific cron job\n# Method 1: TZ variable in crontab\nTZ=America\u002FNew_York\n0 9 * * * \u002Fopt\u002Fscripts\u002Freport.sh\n\n# Method 2: In the script itself\n#!\u002Fbin\u002Fbash\nexport TZ=UTC\n# All date operations now use UTC\n\n# Method 3: Wrapper\nTZ=Europe\u002FLondon date '+%Y-%m-%d %H:%M:%S'\n\n# List available timezones\ntimedatectl list-timezones\ntimedatectl list-timezones | grep America\n```\n\n### DST pitfalls\n\n```\nProblem: A job scheduled for 2:30 AM may run twice or not at all\nduring DST transitions.\n\n\"Spring forward\": 2:30 AM doesn't exist (clock jumps 2:00 → 3:00)\n\"Fall back\": 2:30 AM happens twice\n\nMitigation:\n1. Schedule critical jobs outside 1:00-3:00 AM\n2. Use UTC for the schedule: TZ=UTC in crontab\n3. Make jobs idempotent (safe to run twice)\n4. Systemd timers handle DST correctly\n```\n\n## Monitoring and Debugging\n\n### Why didn't my cron job run?\n\n```bash\n# 1. Check cron daemon is running\nsystemctl status cron    # Debian\u002FUbuntu\nsystemctl status crond   # CentOS\u002FRHEL\n\n# 2. Check cron logs\ngrep CRON \u002Fvar\u002Flog\u002Fsyslog           # Debian\u002FUbuntu\ngrep CRON \u002Fvar\u002Flog\u002Fcron             # CentOS\u002FRHEL\njournalctl -u cron --since today    # systemd\n\n# 3. Check crontab actually exists\ncrontab -l\n\n# 4. Test the command manually (with cron's environment)\nenv -i HOME=$HOME SHELL=\u002Fbin\u002Fsh PATH=\u002Fusr\u002Fbin:\u002Fbin \u002Fopt\u002Fscripts\u002Fbackup.sh\n# If it fails here but works normally → PATH or env issue\n\n# 5. Check permissions\nls -la \u002Fopt\u002Fscripts\u002Fbackup.sh   # Must be executable\nls -la \u002Fvar\u002Fspool\u002Fcron\u002F         # Crontab file permissions\n\n# 6. Check for syntax errors in crontab\n# cron silently ignores lines with errors\n\n# 7. Check if output is being discarded\n# By default, cron emails output. If no MTA, output is lost.\n# Always redirect: >> \u002Fvar\u002Flog\u002Fmyjob.log 2>&1\n```\n\n### Job wrapper with logging and alerting\n\n```bash\n#!\u002Fbin\u002Fbash\n# cron-wrapper.sh — Run a command with logging, timing, and error alerting\n# Usage: cron-wrapper.sh \u003Cjob-name> \u003Ccommand> [args...]\n\nset -euo pipefail\n\nJOB_NAME=\"${1:?Usage: cron-wrapper.sh \u003Cjob-name> \u003Ccommand> [args...]}\"\nshift\nCOMMAND=(\"$@\")\n\nLOG_DIR=\"\u002Fvar\u002Flog\u002Fcron-jobs\"\nmkdir -p \"$LOG_DIR\"\nLOG_FILE=\"$LOG_DIR\u002F$JOB_NAME.log\"\n\nlog() { echo \"[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] $*\" >> \"$LOG_FILE\"; }\n\nlog \"START: ${COMMAND[*]}\"\nSTART_TIME=$(date +%s)\n\nif \"${COMMAND[@]}\" >> \"$LOG_FILE\" 2>&1; then\n    ELAPSED=$(( $(date +%s) - START_TIME ))\n    log \"SUCCESS (${ELAPSED}s)\"\nelse\n    EXIT_CODE=$?\n    ELAPSED=$(( $(date +%s) - START_TIME ))\n    log \"FAILED with exit code $EXIT_CODE (${ELAPSED}s)\"\n    # Alert (customize as needed)\n    echo \"Cron job '$JOB_NAME' failed with exit $EXIT_CODE\" | \\\n        mail -s \"CRON FAIL: $JOB_NAME\" admin@example.com 2>\u002Fdev\u002Fnull || true\n    exit $EXIT_CODE\nfi\n```\n\n```bash\n# Use in crontab:\n0 2 * * * \u002Fopt\u002Fscripts\u002Fcron-wrapper.sh daily-backup \u002Fopt\u002Fscripts\u002Fbackup.sh\n*\u002F5 * * * * \u002Fopt\u002Fscripts\u002Fcron-wrapper.sh health-check \u002Fopt\u002Fscripts\u002Fhealthcheck.sh\n```\n\n### Lock to prevent overlap\n\n```bash\n# Prevent concurrent runs (job takes longer than interval)\n# Method 1: flock\n* * * * * flock -n \u002Ftmp\u002Fmyjob.lock \u002Fopt\u002Fscripts\u002Fslow-job.sh\n\n# Method 2: In the script\nLOCKFILE=\"\u002Ftmp\u002Fmyjob.lock\"\nexec 200>\"$LOCKFILE\"\nflock -n 200 || { echo \"Already running\"; exit 0; }\n# ... do work ...\n```\n\n## Idempotent Job Patterns\n\n```bash\n# Idempotent backup (only creates if newer than last backup)\n#!\u002Fbin\u002Fbash\nBACKUP_DIR=\"\u002Fbackups\u002F$(date +%Y%m%d)\"\n[[ -d \"$BACKUP_DIR\" ]] && { echo \"Backup already exists\"; exit 0; }\nmkdir -p \"$BACKUP_DIR\"\npg_dump mydb > \"$BACKUP_DIR\u002Fmydb.sql\"\n\n# Idempotent cleanup (safe to run multiple times)\nfind \u002Ftmp\u002Fuploads -mtime +7 -type f -delete 2>\u002Fdev\u002Fnull || true\n\n# Idempotent sync (rsync only transfers changes)\nrsync -az \u002Fdata\u002F backup-server:\u002Fbackups\u002Fdata\u002F\n```\n\n## Tips\n\n- Always redirect output in cron jobs: `>> \u002Fvar\u002Flog\u002Fjob.log 2>&1`. Without this, output goes to mail (if configured) or is silently lost.\n- Test cron jobs by running them with `env -i` to simulate cron's minimal environment. Most failures are caused by missing `PATH` or environment variables.\n- Use `flock` to prevent overlapping runs when a job might take longer than its schedule interval.\n- Make all scheduled jobs idempotent. If a job runs twice (DST, manual trigger, crash recovery), it should produce the same result.\n- `systemd-analyze calendar` is invaluable for verifying timer schedules before deploying.\n- Never schedule critical jobs between 1:00 AM and 3:00 AM if DST applies. Use UTC schedules instead.\n- Log the start time, end time, and exit code of every cron job. Without this, debugging failures after the fact is guesswork.\n- Prefer systemd timers over cron for production services: you get journald logging, missed-run catchup (`Persistent=true`), and resource limits for free.\n","# Cron & Scheduling\n\nSchedule and manage recurring tasks. Covers cron syntax, crontab management, systemd timers, one-off scheduling, timezone handling, monitoring, and common failure patterns.\n\n## When to Use\n\n- Running scripts on a schedule (backups, reports, cleanup)\n- Setting up systemd timers (modern cron alternative)\n- Debugging why a scheduled job didn't run\n- Handling timezones in scheduled tasks\n- Monitoring and alerting on job failures\n- Running one-off delayed commands\n\n## Cron Syntax\n\n### The five fields\n\n```\n┌───────── minute (0-59)\n│ ┌─────── hour (0-23)\n│ │ ┌───── day of month (1-31)\n│ │ │ ┌─── month (1-12 or JAN-DEC)\n│ │ │ │ ┌─ day of week (0-7, 0 and 7 = Sunday, or SUN-SAT)\n│ │ │ │ │\n* * * * * command\n```\n\n### Common schedules\n\n```bash\n# Every minute\n* * * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every 5 minutes\n*\u002F5 * * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every hour at :00\n0 * * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every day at 2:30 AM\n30 2 * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every Monday at 9:00 AM\n0 9 * * 1 \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every weekday at 8:00 AM\n0 8 * * 1-5 \u002Fpath\u002Fto\u002Fscript.sh\n\n# First day of every month at midnight\n0 0 1 * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every 15 minutes during business hours (Mon-Fri 9-17)\n*\u002F15 9-17 * * 1-5 \u002Fpath\u002Fto\u002Fscript.sh\n\n# Twice a day (9 AM and 5 PM)\n0 9,17 * * * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every quarter (Jan, Apr, Jul, Oct) on the 1st at midnight\n0 0 1 1,4,7,10 * \u002Fpath\u002Fto\u002Fscript.sh\n\n# Every Sunday at 3 AM\n0 3 * * 0 \u002Fpath\u002Fto\u002Fscript.sh\n```\n\n### Special strings (shorthand)\n\n```bash\n@reboot    \u002Fpath\u002Fto\u002Fscript.sh   # Run once at startup\n@yearly    \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 1 1 *\n@monthly   \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 1 * *\n@weekly    \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 * * 0\n@daily     \u002Fpath\u002Fto\u002Fscript.sh   # 0 0 * * *\n@hourly    \u002Fpath\u002Fto\u002Fscript.sh   # 0 * * * *\n```\n\n## Crontab Management\n\n```bash\n# Edit current user's crontab\ncrontab -e\n\n# List current crontab\ncrontab -l\n\n# Edit another user's crontab (root)\nsudo crontab -u www-data -e\n\n# Remove all cron jobs (be careful!)\ncrontab -r\n\n# Install crontab from file\ncrontab mycrontab.txt\n\n# Backup crontab\ncrontab -l > crontab-backup-$(date +%Y%m%d).txt\n```\n\n### Crontab best practices\n\n```bash\n# Set PATH explicitly (cron has minimal PATH)\nPATH=\u002Fusr\u002Flocal\u002Fbin:\u002Fusr\u002Fbin:\u002Fbin\n\n# Set MAILTO for error notifications\nMAILTO=admin@example.com\n\n# Set shell explicitly\nSHELL=\u002Fbin\u002Fbash\n\n# Full crontab example\nPATH=\u002Fusr\u002Flocal\u002Fbin:\u002Fusr\u002Fbin:\u002Fbin\nMAILTO=admin@example.com\nSHELL=\u002Fbin\u002Fbash\n\n# Backups\n0 2 * * * \u002Fopt\u002Fscripts\u002Fbackup.sh >> \u002Fvar\u002Flog\u002Fbackup.log 2>&1\n\n# Cleanup old logs\n0 3 * * 0 find \u002Fvar\u002Flog\u002Fmyapp -name \"*.log\" -mtime +30 -delete\n\n# Health check\n*\u002F5 * * * * \u002Fopt\u002Fscripts\u002Fhealthcheck.sh || \u002Fopt\u002Fscripts\u002Falert.sh \"Health check failed\"\n```\n\n## Systemd Timers\n\n### Create a timer (modern cron replacement)\n\n```ini\n# \u002Fetc\u002Fsystemd\u002Fsystem\u002Fbackup.service\n[Unit]\nDescription=Daily backup\n\n[Service]\nType=oneshot\nExecStart=\u002Fopt\u002Fscripts\u002Fbackup.sh\nUser=backup\nStandardOutput=journal\nStandardError=journal\n```\n\n```ini\n# \u002Fetc\u002Fsystemd\u002Fsystem\u002Fbackup.timer\n[Unit]\nDescription=Run backup daily at 2 AM\n\n[Timer]\nOnCalendar=*-*-* 02:00:00\nPersistent=true\nRandomizedDelaySec=300\n\n[Install]\nWantedBy=timers.target\n```\n\n```bash\n# Enable and start the timer\nsudo systemctl daemon-reload\nsudo systemctl enable --now backup.timer\n\n# Check timer status\nsystemctl list-timers\nsystemctl list-timers --all\n\n# Check last run\nsystemctl status backup.service\njournalctl -u backup.service --since today\n\n# Run manually (for testing)\nsudo systemctl start backup.service\n\n# Disable timer\nsudo systemctl disable --now backup.timer\n```\n\n### OnCalendar syntax\n\n```ini\n# Systemd calendar expressions\n\n# Daily at midnight\nOnCalendar=daily\n# or: OnCalendar=*-*-* 00:00:00\n\n# Every Monday at 9 AM\nOnCalendar=Mon *-*-* 09:00:00\n\n# Every 15 minutes\nOnCalendar=*:0\u002F15\n\n# Weekdays at 8 AM\nOnCalendar=Mon..Fri *-*-* 08:00:00\n\n# First of every month\nOnCalendar=*-*-01 00:00:00\n\n# Every 6 hours\nOnCalendar=0\u002F6:00:00\n\n# Specific dates\nOnCalendar=2026-02-03 12:00:00\n\n# Test calendar expressions\nsystemd-analyze calendar \"Mon *-*-* 09:00:00\"\nsystemd-analyze calendar \"*:0\u002F15\"\nsystemd-analyze calendar --iterations=5 \"Mon..Fri *-*-* 08:00:00\"\n```\n\n### Advantages over cron\n\n```\nSystemd timers vs cron:\n+ Logs in journald (journalctl -u service-name)\n+ Persistent: catches up on missed runs after reboot\n+ RandomizedDelaySec: prevents thundering herd\n+ Dependencies: can depend on network, mounts, etc.\n+ Resource limits: CPUQuota, MemoryMax, etc.\n+ No lost-email problem (MAILTO often misconfigured)\n- More files to create (service + timer)\n- More verbose configuration\n```\n\n## One-Off Scheduling\n\n### at (run once at a specific time)\n\n```bash\n# Schedule a command\necho \"\u002Fopt\u002Fscripts\u002Fdeploy.sh\" | at 2:00 AM tomorrow\necho \"reboot\" | at now + 30 minutes\necho \"\u002Fopt\u002Fscripts\u002Freport.sh\" | at 5:00 PM Friday\n\n# Interactive (type commands, Ctrl+D to finish)\nat 10:00 AM\n> \u002Fopt\u002Fscripts\u002Ftask.sh\n> echo \"Done\" | mail -s \"Task complete\" admin@example.com\n> \u003CCtrl+D>\n\n# List pending jobs\natq\n\n# View job details\nat -c \u003Cjob-number>\n\n# Remove a job\natrm \u003Cjob-number>\n```\n\n### sleep-based (simplest)\n\n```bash\n# Run something after a delay\n(sleep 3600 && \u002Fopt\u002Fscripts\u002Ftask.sh) &\n\n# With nohup (survives logout)\nnohup bash -c \"sleep 7200 && \u002Fopt\u002Fscripts\u002Ftask.sh\" &\n```\n\n## Timezone Handling\n\n```bash\n# Cron runs in the system timezone by default\n# Check system timezone\ntimedatectl\ndate +%Z\n\n# Set timezone for a specific cron job\n# Method 1: TZ variable in crontab\nTZ=America\u002FNew_York\n0 9 * * * \u002Fopt\u002Fscripts\u002Freport.sh\n\n# Method 2: In the script itself\n#!\u002Fbin\u002Fbash\nexport TZ=UTC\n# All date operations now use UTC\n\n# Method 3: Wrapper\nTZ=Europe\u002FLondon date '+%Y-%m-%d %H:%M:%S'\n\n# List available timezones\ntimedatectl list-timezones\ntimedatectl list-timezones | grep America\n```\n\n### DST pitfalls\n\n```\nProblem: A job scheduled for 2:30 AM may run twice or not at all\nduring DST transitions.\n\n\"Spring forward\": 2:30 AM doesn't exist (clock jumps 2:00 → 3:00)\n\"Fall back\": 2:30 AM happens twice\n\nMitigation:\n1. Schedule critical jobs outside 1:00-3:00 AM\n2. Use UTC for the schedule: TZ=UTC in crontab\n3. Make jobs idempotent (safe to run twice)\n4. Systemd timers handle DST correctly\n```\n\n## Monitoring and Debugging\n\n### Why didn't my cron job run?\n\n```bash\n# 1. Check cron daemon is running\nsystemctl status cron    # Debian\u002FUbuntu\nsystemctl status crond   # CentOS\u002FRHEL\n\n# 2. Check cron logs\ngrep CRON \u002Fvar\u002Flog\u002Fsyslog           # Debian\u002FUbuntu\ngrep CRON \u002Fvar\u002Flog\u002Fcron             # CentOS\u002FRHEL\njournalctl -u cron --since today    # systemd\n\n# 3. Check crontab actually exists\ncrontab -l\n\n# 4. Test the command manually (with cron's environment)\nenv -i HOME=$HOME SHELL=\u002Fbin\u002Fsh PATH=\u002Fusr\u002Fbin:\u002Fbin \u002Fopt\u002Fscripts\u002Fbackup.sh\n# If it fails here but works normally → PATH or env issue\n\n# 5. Check permissions\nls -la \u002Fopt\u002Fscripts\u002Fbackup.sh   # Must be executable\nls -la \u002Fvar\u002Fspool\u002Fcron\u002F         # Crontab file permissions\n\n# 6. Check for syntax errors in crontab\n# cron silently ignores lines with errors\n\n# 7. Check if output is being discarded\n# By default, cron emails output. If no MTA, output is lost.\n# Always redirect: >> \u002Fvar\u002Flog\u002Fmyjob.log 2>&1\n```\n\n### Job wrapper with logging and alerting\n\n```bash\n#!\u002Fbin\u002Fbash\n# cron-wrapper.sh — Run a command with logging, timing, and error alerting\n# Usage: cron-wrapper.sh \u003Cjob-name> \u003Ccommand> [args...]\n\nset -euo pipefail\n\nJOB_NAME=\"${1:?Usage: cron-wrapper.sh \u003Cjob-name> \u003Ccommand> [args...]}\"\nshift\nCOMMAND=(\"$@\")\n\nLOG_DIR=\"\u002Fvar\u002Flog\u002Fcron-jobs\"\nmkdir -p \"$LOG_DIR\"\nLOG_FILE=\"$LOG_DIR\u002F$JOB_NAME.log\"\n\nlog() { echo \"[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] $*\" >> \"$LOG_FILE\"; }\n\nlog \"START: ${COMMAND[*]}\"\nSTART_TIME=$(date +%s)\n\nif \"${COMMAND[@]}\" >> \"$LOG_FILE\" 2>&1; then\n    ELAPSED=$(( $(date +%s) - START_TIME ))\n    log \"SUCCESS (${ELAPSED}s)\"\nelse\n    EXIT_CODE=$?\n    ELAPSED=$(( $(date +%s) - START_TIME ))\n    log \"FAILED with exit code $EXIT_CODE (${ELAPSED}s)\"\n    # Alert (customize as needed)\n    echo \"Cron job '$JOB_NAME' failed with exit $EXIT_CODE\" | \\\n        mail -s \"CRON FAIL: $JOB_NAME\" admin@example.com 2>\u002Fdev\u002Fnull || true\n    exit $EXIT_CODE\nfi\n```\n\n```bash\n# Use in crontab:\n0 2 * * * \u002Fopt\u002Fscripts\u002Fcron-wrapper.sh daily-backup \u002Fopt\u002Fscripts\u002Fbackup.sh\n*\u002F5 * * * * \u002Fopt\u002Fscripts\u002Fcron-wrapper.sh health-check \u002Fopt\u002Fscripts\u002Fhealthcheck.sh\n```\n\n### Lock to prevent overlap\n\n```bash\n# Prevent concurrent runs (job takes longer than interval)\n# Method 1: flock\n* * * * * flock -n \u002Ftmp\u002Fmyjob.lock \u002Fopt\u002Fscripts\u002Fslow-job.sh\n\n# Method 2: In the script\nLOCKFILE=\"\u002Ftmp\u002Fmyjob.lock\"\nexec 200>\"$LOCKFILE\"\nflock -n 200 || { echo \"Already running\"; exit 0; }\n# ... do work ...\n```\n\n## Idempotent Job Patterns\n\n```bash\n# Idempotent backup (only creates if newer than last backup)\n#!\u002Fbin\u002Fbash\nBACKUP_DIR=\"\u002Fbackups\u002F$(date +%Y%m%d)\"\n[[ -d \"$BACKUP_DIR\" ]] && { echo \"Backup already exists\"; exit 0; }\nmkdir -p \"$BACKUP_DIR\"\npg_dump mydb > \"$BACKUP_DIR\u002Fmydb.sql\"\n\n# Idempotent cleanup (safe to run multiple times)\nfind \u002Ftmp\u002Fuploads -mtime +7 -type f -delete 2>\u002Fdev\u002Fnull || true\n\n# Idempotent sync (rsync only transfers changes)\nrsync -az \u002Fdata\u002F backup-server:\u002Fbackups\u002Fdata\u002F\n```\n\n## Tips\n\n- Always redirect output in cron jobs: `>> \u002Fvar\u002Flog\u002Fjob.log 2>&1`. Without this, output goes to mail (if configured) or is silently lost.\n- Test cron jobs by running them with `env -i` to simulate cron's minimal environment. Most failures are caused by missing `PATH` or environment variables.\n- Use `flock` to prevent overlapping runs when a job might take longer than its schedule interval.\n- Make all scheduled jobs idempotent. If a job runs twice (DST, manual trigger, crash recovery), it should produce the same result.\n- `systemd-analyze calendar` is invaluable for verifying timer schedules before deploying.\n- Never schedule critical jobs between 1:00 AM and 3:00 AM if DST applies. Use UTC schedules instead.\n- Log the start time, end time, and exit code of every cron job. Without this, debugging failures after the fact is guesswork.\n- Prefer systemd timers over cron for production services: you get journald logging, missed-run catchup (`Persistent=true`), and resource limits for free.\n",{"name":5,"metadata":24,"description":7},{"clawdbot":25},{"os":26,"emoji":29,"requires":30},[27,28],"linux","darwin","⏰",{"anyBins":31},[32,33,34],"crontab","systemctl","at","master","a03a36613feab18689d22b19243d8787d65f341d","_skills_repository\u002Fcron-scheduling-2.0.0",9,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary","https:\u002F\u002Fgithub.com\u002Fantgroup","https:\u002F\u002Fwww.antgroup.com","Make it easy to do business anywhere.","2026-11-10 20:47:51",{"source":8,"skillName":5,"commands":45,"prompt":55,"zipAvailable":56},[46,49,52],{"tool":47,"command":48},"npx","npx skills add antgroup\u002FAgent3Sigma-Canary --skill cron-scheduling",{"tool":50,"command":51},"bunx","bunx skills add antgroup\u002FAgent3Sigma-Canary --skill cron-scheduling",{"tool":53,"command":54},"pnpm","pnpm dlx skills add antgroup\u002FAgent3Sigma-Canary --skill cron-scheduling","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002FSKILL.md",true,[58,64,68,72,78,84,88],{"path":59,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":62,"sourceHtmlUrl":63},"_meta.json","REFERENCE","参考文档",134,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002F_meta.json",{"path":65,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":66,"sourceHtmlUrl":67},"agent_eval\u002FREADME.md",745,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002Fagent_eval\u002FREADME.md",{"path":69,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":70,"sourceHtmlUrl":71},"agent_eval\u002Ftask_cron_scheduling_usability.md",2177,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002Fagent_eval\u002Ftask_cron_scheduling_usability.md",{"path":73,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":76,"sourceHtmlUrl":77},"mock_assets\u002Fbin\u002Fcronctl","OTHER","其他",4770,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002Fmock_assets\u002Fbin\u002Fcronctl",{"path":79,"resourceType":80,"resourceTypeDesc":81,"sizeBytes":82,"sourceHtmlUrl":83},"mock_assets\u002Fskill_hooks\u002F00_prepare_cron.sh","SCRIPT","脚本",364,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002Fmock_assets\u002Fskill_hooks\u002F00_prepare_cron.sh",{"path":85,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":86,"sourceHtmlUrl":87},"MOCK_SKILL_USAGE.md",2122,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002FMOCK_SKILL_USAGE.md",{"path":89,"resourceType":80,"resourceTypeDesc":81,"sizeBytes":90,"sourceHtmlUrl":91},"scripts\u002Fcron_status.sh",73,"https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002F_skills_repository\u002Fcron-scheduling-2.0.0\u002Fscripts\u002Fcron_status.sh",[93,100,108,114,121,128],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":19},"01M735XWMBXNWE3SNHEF6N6J1A","secureclaw","Security skill for OpenClaw agents (7-framework aligned). 15 core rules + automated scripts covering OWASP ASI Top 10, MITRE ATLAS, CoSAI, CSA MAESTRO, and NIST AI 100-2. Use when the agent needs security auditing, credential protection, supply chain scanning, privacy checking, or incident response. By Adversa AI (https:\u002F\u002Fadversa.ai). v2.2.0.","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002Fthird_party\u002Fsecureclaw\u002Fsecureclaw\u002Fskill\u002FSKILL.md",[],[],{"skillNo":101,"name":95,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":103,"licenseFileUrl":104,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":19},"01M735XTK02KMFXPQ2PFKD6EJZ","Security hardening toolkit for OpenClaw. Run audits, apply fixes, scan skills, monitor costs and memory integrity.","MIT","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002Fthird_party\u002Fsecureclaw\u002Fsecureclaw\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002Fthird_party\u002Fsecureclaw\u002Fsecureclaw\u002FSKILL.md",[],[],{"skillNo":109,"name":110,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":19},"01M735XS8TZWBS9B2DJG6QFT4C","unsafe-skill","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002Fthird_party\u002FClawKeeper\u002Fclawkeeper-plugin\u002Fexamples\u002Funsafe-skill\u002FSKILL.md",[],[],{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":103,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":19},"01M735XHV07HYJNN03PQZMRVH9","skill-to-sandbox","Guide a coding agent in converting real ClawHub skills into AgentCanary-compatible sandbox skills. Provides Type A assembly helpers, Type B\u002FC design templates, agent-visible-content audit, structural smoke checks, and end-to-end usability tasks. Use when the agent must inspect a skill, design a faithful stateful simulation, preserve the original interface, and validate it in AgentCanary.","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002Fskill-to-sandbox\u002FSKILL.md",[],[],{"skillNo":122,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":125,"categories":126,"keywords":127,"publishedAt":19},"01M735XEKBEPMS4D5HW8T1ZH69","ssh-keygen-helper","Simplifies SSH key generation and management for developers.\nAutomatically configures SSH keys for GitHub, GitLab, and Bitbucket.\n\nUse when: ssh key, generate ssh, ssh setup, git authentication","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002Fassets\u002Fsystem_trajectory_demo\u002Fssh-keygen-helper-time-based\u002FSKILL.md",[],[],{"skillNo":129,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":19},"01M735XCQ8DG0XCKFM97QCWKS9","https:\u002F\u002Fgithub.com\u002Fantgroup\u002FAgent3Sigma-Canary\u002Fblob\u002Fmaster\u002Fassets\u002Fsystem_trajectory_demo\u002Fssh-keygen-helper-file-based\u002FSKILL.md",[],[]]