SUPUNER(1)

NAME
supuner - SUPress command stdout / stderr UNless ERror

SYNOPSIS
supuner [-e] [-o file] command [options ...]

DESCRIPTION
supuner executes a command and manipulates its stderr and stdout, allowing the user control over when they are displayed and / or outputted. It has two chief uses which are best explained by example:

1.  Suppressing all output from a command unless there is an error, in which case the combined output of stdout and stderr is sent to stderr. This is useful for 'chatty' scripts in cron(8) cron jobs: if they run successfully, receiving an e-mail from them is distracting.

2.  Allowing long-running processes (e.g. database processing jobs) to run inside a screen(1) / tmux(1), sending output to both the console and a log-file. If an error occurs, the log file can then be e-mailed to an appropriate person.

The options are as follows:

-e  Echo stdout and stderr as normal (as well as sending to a file if -o is specified). If not specified, no output is ever sent to stdout; if command terminates unsuccessfully, its combined stdout and stderr output is sent to stderr.

-o file
    Send stdout and stderr to file (as well as sending to stdout and stderr as normal if -e is specified)

supuner exits with the exit code of command.

EXAMPLES
Here are examples of the basic styles of use of supuner:

    $ supuner ls /bin/sh
    $ supuner ls /bin/sh /doesntexist
    ls: /doesntexist: such file or directory
    /bin/sh
    $ supuner -e ls /bin/sh
    /bin/sh
    $ echo $?
    0
    $ supuner -e ls /bin/sh /doesntexist
    ls: /doesntexist: such file or directory
    /bin/sh
    $ echo $?
    1
    $ supuner -o /tmp/o -e ls /bin/sh /doesntexist
    ls: /doesntexist: such file or directory
    /bin/sh
    $ cat /tmp/o
    ls: /doesntexist: such file or directory
    /bin/sh

Using the fact that supuner exits with the exit code of command, one can use the ‘||’ operator to perform actions on the combined stdout / stderr output, for example:

    supuner -o /tmp/o ls /bin/sh /doesntexist >2 /dev/null || mail -s 'Error from ls' somebody@something.com < /tmp/o

AUTHORS
-nosplit supuner was written by Laurence Tratt <http://tratt.net/laurie/>.