{"id":"code-dev-crontab-line-flock-utc","audience":"developers","category":"coding","track":"coding","technique":"context","title":"Write one crontab line that won't overlap or lose logs","free":false,"task":"Schedule the nightly ledger job as a single crontab line. It must run on weekdays at 06:30 UTC (the server clock is UTC). Your team's rule is that every job is wrapped in flock -n with its own lock file, here /tmp/ledger.lock, and calls the script by its absolute path. Append both stdout and stderr to /var/log/ledger/nightly.log. Exactly 1 code block containing 1 line, under 40 words of text.","materialLabel":"The job's README (attached to your prompt automatically)","material":"# ledger-nightly\n\nRebuilds the daily ledger summaries for Copperleaf Accounting's\nclient portal.\n\n## Install\n    sudo cp bin/nightly.sh /opt/ledger/bin/nightly.sh\n    sudo chmod +x /opt/ledger/bin/nightly.sh\n    sudo mkdir -p /var/log/ledger\n\n## Schedule\nRuns every day at 7:00 (old schedule from when the box was in\nAmerica/Chicago; we moved to the UTC box in August).\n\n## Notes\n- Takes 10-40 minutes depending on month-end volume.\n- On Oct 31 a slow run was still going when the next one started and\n  both wrote to the same summary table. Took a day to untangle.\n- The script uses relative paths internally but cds to its own dir\n  first, so it's fine to call from anywhere.\n- Logs: the script prints progress to stdout and errors to stderr.\n- Cron on this box: Debian 12, vixie-cron, SHELL=/bin/sh.\n\n## Current crontab (to be replaced)\n0 7 * * * cd /opt/ledger/bin && ./nightly.sh","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":1},{"type":"maxProseWords","max":40}],"mistakes":[{"title":"Copying the old schedule","why":"The README still says 7:00 daily, from the old time zone.","fix":"Add: \"Weekdays at 06:30 UTC; the server clock is UTC.\"","checks":["r0"]},{"title":"Overlapping runs","why":"Without a lock, a slow month-end run collides with the next one, like on Oct 31.","fix":"Add: \"Wrap it in flock -n /tmp/ledger.lock.\"","checks":["r1"]},{"title":"Losing the errors","why":"A plain > or >> without 2>&1 drops stderr, which is where failures go.","fix":"Add: \"Append stdout and stderr: >> /var/log/ledger/nightly.log 2>&1.\"","checks":["r2"]},{"title":"A cron tutorial","why":"The AI explains the five fields and suggests systemd timers.","fix":"Add: \"One code block with one line, nothing else.\"","checks":["codeBlocks","maxCodeLines","maxProseWords"]}],"promptHints":[{"label":"Gives the schedule","patterns":["weekday","6:30","06:30","1-5"]},{"label":"Mentions UTC","patterns":["utc"]},{"label":"Asks for a lock","patterns":["flock","lock","overlap"]},{"label":"Gives the log path","patterns":["nightly\\.log","2>&1","stderr"]},{"label":"Asks for one line","patterns":["one line","single line","only the (line|crontab)"]}],"hint":"The README is out of date, and your team has rules for every job. Tell the AI the real schedule, the lock, the path and where both outputs go.","rubricLabels":["The schedule fields are 30 6 * * 1-5 (06:30, Monday to Friday), not the old 7:00 daily","Wraps the job as flock -n /tmp/ledger.lock /opt/ledger/bin/nightly.sh, with the script's absolute path and no cd","Ends with >> /var/log/ledger/nightly.log 2>&1 so both stdout and stderr are appended"]}