On Mon, Dec 09, 2024 at 17:08:31 +0000, Darac Marjal wrote:
> A helpful tool here might be "cronic" (in the "cronic" package). "cronic"
> will swallow the output of the command it runs UNLESS that command exits
> with an error code.
> 
> So one would write:
> 
> 3 8 * * * cronic /usr/local/bin/hearbeat-watcher.sh
> 
> and let's imagine the shell script does "echo Everything's okay ; exit 0"
> once a day, then you don't get too many emails. But when it fails (echo
> Everything's not okay ; exit 1), then you DO get an email.

That depends on the script exiting with an appropriate code.  May work,
may not.

If the "all's well" messages are printed to stdout, and the real errors
are printed to stderr, then it might be simpler just to redirect
stdout BUT NOT redirect stderr.

    3 8 * * * /usr/local/bin/heartbeat-watcher.sh >/dev/null

Then, if anything is written to stderr, cron will email it.

Of course, this depends on the script printing error messages to stderr.
May work, may not.

Reply via email to