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 [-ehf] command [arg ...]
PARAMETERS
-e
Echo the command line before executing it.
-h
Display usage help and exit.
-f
Force exit with the command's status even if successful (no suppression).
DESCRIPTION
The chronic command, part of the moreutils package, executes a given command and suppresses its standard output and standard error if the command succeeds (exit status 0). If the command fails (non-zero exit status), chronic prints the command's output along with its exit status.
This is particularly useful in cron jobs or scripts where you want to run maintenance tasks silently but get notified on failures. For example, chronic mysqldump -u user db > backup.sql will only output if the dump fails.
Unlike redirection to /dev/null, it preserves failure output without complex conditional logic. It's a lightweight wrapper enhancing script reliability.
CAVEATS
Does not handle very large outputs well if failure occurs; relies on moreutils package installation.
EXIT STATUS
Exits with 0 if command succeeds or is suppressed; otherwise, command's exit status.
INSTALLATION
Available via apt install moreutils on Debian/Ubuntu or equivalent.
HISTORY
Introduced in the moreutils package by Joey Hess in 2007; designed for Unix-like systems to simplify cron scripting by auto-suppressing success output.


