Library › Coding AI › Software developers

Write one crontab line that won't overlap or lose logs

Practice: Giving the right context. About 5 minutes.

About this exercise

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.

Common mistakes when you ask AI for this

  • Copying the old schedule. The README still says 7:00 daily, from the old time zone. Try: Add: "Weekdays at 06:30 UTC; the server clock is UTC."
  • Overlapping runs. Without a lock, a slow month-end run collides with the next one, like on Oct 31. Try: Add: "Wrap it in flock -n /tmp/ledger.lock."
  • Losing the errors. A plain > or >> without 2>&1 drops stderr, which is where failures go. Try: Add: "Append stdout and stderr: >> /var/log/ledger/nightly.log 2>&1."
  • A cron tutorial. The AI explains the five fields and suggests systemd timers. Try: Add: "One code block with one line, nothing else."

What a strong prompt includes

  • Gives the schedule
  • Mentions UTC
  • Asks for a lock
  • Gives the log path
  • Asks for one line

Practice this now ↑

Related exercises