chronic
Run command quietly unless it fails
TLDR
Display stdout and stderr of the specified command if and only if it produces a non-zero exit code or crashes
Display stdout and stderr of the specified command if and only if it produces a non-empty stderr
Enable [v]erbose mode
SYNOPSIS
chronic command [arg...]
PARAMETERS
command
The command to be executed by chronic.
[arg...]
Optional arguments to be passed to the command.
DESCRIPTION
The chronic command executes a given command and only displays its standard output and standard error if the command fails (i.e., returns a a non-zero exit status) or if it produces any output. If the command succeeds and produces no output, chronic suppresses all output. This utility is particularly useful in automated scripts, especially cron jobs, where you typically only want to be notified if something goes wrong or if there's important information to convey. By wrapping commands with chronic, system administrators can avoid receiving email notifications for routine, successful, and silent tasks, thus reducing inbox clutter and making it easier to spot actual issues. It acts as a filter, allowing silent success and verbose failure.
CAVEATS
If the wrapped command produces output but exits successfully (status 0), chronic will still print the output. It only suppresses output if both conditions are met: success and no output.
chronic is primarily designed for non-interactive, automated tasks and may not behave as expected with interactive commands.
EXIT STATUS
The exit status of chronic itself is the exit status of the command it runs. This allows scripts to directly check the success or failure of the wrapped command, even when using chronic.
USE IN CRON
One of its primary and most beneficial use cases is within cron entries. For example, instead of a simple `0 * * * * /usr/local/bin/backup.sh`, you might use `0 * * * * chronic /usr/local/bin/backup.sh`. This ensures that only failures or explicit output from the backup script will generate email notifications, significantly reducing inbox clutter.
HISTORY
chronic is a utility part of the moreutils package, a collection of small, useful Unix utilities. The package was created by Joey Hess, and chronic has been a fundamental component since its early days, specifically designed to address the common problem of excessive email notifications from cron jobs for successful, silent operations.