How to Silence Successful Cron Jobs and Scripts in Linux Using the chronic Command

Managing scheduled cron jobs and automated maintenance scripts in Linux frequently exposes system administrators to the “cron spam” dilemma. The default cron daemon captures all standard output (stdout) and standard error (stderr) emitted by scheduled tasks and emails the entire transcript to the server administrator or local mail spool. Consequently, scripts that output routine progress logs generate dozens of unnecessary emails every day.

A common but dangerous workaround is redirecting all output to oblivion using >/dev/null 2>&1. However, completely discarding output blinds administrators when a critical job fails, because errors and backtraces are permanently lost. The standard Linux utility chronic solves this dilemma elegantly by buffering output and displaying it only when an error occurs.

How chronic Solves Automated Job Logging

The chronic utility, distributed as part of the GNU/Debian moreutils package, wraps any command execution:

  • It executes the wrapped command while silently buffering all stdout and stderr streams in memory.
  • If the wrapped command exits with a status code of 0 (success), chronic discards the buffered text completely, producing zero output.
  • If the command fails and exits with a non-zero exit code (or is terminated by a signal), chronic immediately flushes both stdout and stderr to the console.

This guarantees that routine successful runs remain completely quiet, while failed operations deliver full diagnostics directly to your email or alerting pipeline.

Installing moreutils on Linux

To acquire the chronic command, install the moreutils package on your system:

  • Ubuntu / Debian / Linux Mint:
    sudo apt update && sudo apt install moreutils
  • Fedora / RHEL / AlmaLinux:
    sudo dnf install moreutils
  • Arch Linux:
    sudo pacman -S moreutils

Basic Command-Line Usage

To demonstrate how chronic handles output, consider a script that outputs verbose messages during normal operation:

chronic ./nightly_backup.sh

If nightly_backup.sh completes successfully with exit code 0, nothing is printed to the terminal. But if the script fails (e.g. database connection refused or disk full), chronic dumps the entire verbose execution log to stderr.

Comparing standard redirection with chronic

Consider the differences when configuring crontab entries:

  • Standard Output (Noisy):
    0 2 * * * /usr/local/bin/backup_database.sh
    Sends an email every night containing “Connecting… Dumping tables… 100% complete.”
  • Blind Redirection (Dangerous):
    0 2 * * * /usr/local/bin/backup_database.sh >/dev/null 2>&1
    Zero noise, but if the database crashes, nobody is alerted and backups fail silently.
  • The chronic Approach (Safe & Clean):
    0 2 * * * chronic /usr/local/bin/backup_database.sh
    Zero emails on success. When a backup fails, an email arrives immediately containing the exact failure reason.

Handling Pipelines and Multiple Commands

When running a pipeline inside a crontab or shell script, wrap the entire subshell inside chronic:

chronic sh -c "curl -sS https://api.example.com/health | jq -e .healthy"

Here, jq -e returns an exit code of 0 if .healthy evaluates to true. If the health check fails, chronic prints the invalid JSON response immediately for triage.

Deploying chronic across your server automation eliminates notification fatigue while preserving complete visibility into operational failures.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.