The problem with a cron job is that the moment it matters, you are not looking at it. Cron runs quietly, mails are easy to miss, and a job that fails at 03:00 leaves no sign until you go hunting for it. The direct answer: I route every scheduled task through a wrapper script instead of pointing cron at the tool directly, and the wrapper does three things - it logs everything, it returns a real exit code, and it fails loud. That small indirection is what turns an invisible job into one I can actually operate. Here is how the pattern works and why I run all my scheduled automation through it.
Why point cron at a wrapper, not the tool
Cron does one thing well: it runs a command at a time. It does not care about the output, it does not preserve your shell environment, and if the command's exit code is not your command's exit code, you never know what really happened. When I point cron straight at a tool, the tool's stdout goes into the void and a failure is a one-line mail with no context.
Every cron entry on my hosts points at a wrapper script instead. I keep one reusable wrapper in my automation config, and every scheduled job calls it. The wrapper runs the real command, captures what it produces, and handles the bookkeeping around it. That one script is the single place where logging, exit handling, and notification live, so I do not re-implement them for each new schedule. A new job becomes a one-line registry entry plus this same wrapper - which is exactly the setup I describe in my notes on running agents unattended.
What the wrapper must do
I hold my wrapper to four properties, and any script that does not meet all of them is not a wrapper worth having.
First, it logs everything. Output goes into a date-stamped directory, so each run has its own place and I can page back through history without untangling interleaved logs. If I cannot see what a run did, I cannot diagnose it.
Second, it exits with a code. The wrapper captures the real command's exit status and propagates it, rather than swallowing it. Cron's mail hook and any notify logic key off that code, so a non-zero exit actually travels somewhere. An exit code that gets lost is the same as no exit code at all.
Third, it is re-runnable. The wrapper is idempotent - running it twice does not corrupt state or duplicate side effects. That matters because re-running is my primary recovery action, and a wrapper that cannot be safely re-run turns a failure into a crisis.
Fourth, it fails loud. A quiet success and a loud failure are the two states I care about. The wrapper makes sure failure is obvious rather than silent, which ties directly into the notification loop I discuss in my post on notification emails.
The exit code is the contract
The most important line in the wrapper is the one that propagates the exit code. In practice that means the wrapper ends with something that returns the real command's status - not a hardcoded zero, and not a chain of commands where the last one's status is unrelated to the actual work.
Once the exit code is real, the rest of the chain works. Cron sees a failure. The notify hook sees non-zero and fires. The monitoring that watches for dead jobs sees a missed or failed run. Everything downstream of the wrapper is simple because the wrapper kept the contract honest. If the wrapper had collapsed every outcome into "ran and exited zero", none of that would be possible.
Fail loud, stay quiet on success
I want noise when something breaks and near-silence when it does not. The wrapper's log-and-exit design gives me that: success produces a line in the log and a clean exit, failure produces the log tail, the exit code, and - because my notification wrapper reads that code - an immediate alert with the re-run command. A job that runs but never notifies is already dead in the sense that matters, so the wrapper treats notification as part of the job itself.
I do not present this as a finished artifact; my wrapper evolves every time I schedule something new. The core invariants - log everything, return an exit code, be re-runnable, fail loud - have not changed, and they have saved me more than one late-night chase. What does your wrapper do when a run fails: does the exit code actually reach anyone, or does it silently vanish into cron's void?
Originally published at agentjournal.dev.
