supuner(SUPpress UNless ERror) 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:
- Suppressing all output from a command unless there is an error, in which case the combined output of stderr and stdout is sent to stderr. This is useful for `chatty' scripts in cron jobs: if they run successfully, receiving an e-mail from them is distracting.
- For long-running processes (e.g. database processing jobs running inside
tmux), 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.
- supuner 0.1 (2011/06/19) (4Kb)
- First public release.
You can also view supuner's git history. Patches are always gratefully received.
UsageThe command-line arguments are as follows:
supuner [-e] [-o <filename>] <command>Where:
||By default |
||is a file to store combined stderr / stdout output. Can be combined with -e if desired.|
||is the program, plus arguments, for execution.|
supunerexits with the exit code of
Here are examples of the basic styles of use of
$ supuner ls /bin/sh $ supuner ls /bin/sh /doesntexist ls: /doesntexist: No such file or directory /bin/sh $ supuner -e ls /bin/sh /bin/sh $ echo $? 0 $ supuner -e ls /bin/sh /doesntexist ls: /doesntexist: No such file or directory /bin/sh $ echo $? 1 $ supuner -o /tmp/o -e ls /bin/sh /doesntexist ls: /doesntexist: No such file or directory /bin/sh $ cat /tmp/o ls: /doesntexist: No such file or directory /bin/sh $Taking this, we can then do some more useful things. For example, we can run a command, see its output in the console, and log that to a file; if the command fails, we can then e-mail the relevant person with the copy of the log:
$ supuner -o /tmp/o -e ls /bin/sh /doesntexist \ || mail -s "Error from ls" firstname.lastname@example.org < /tmp/o ls: /doesntexist: No such file or directory /bin/sh $If we want to do the same thing but without sending any output at all to the console we can do the following:
$ supuner -o /tmp/o ls /bin/sh /doesntexist >2 /dev/null \ || mail -s "Error from ls" email@example.com < /tmp/o
On one machine I run, there is a command (let's call it
cmd) running in an infinite loop which prints to
stdout. It runs inside a
tmuxso that I can login and see its current progress. However, if
cmdthrows an error, I want to be e-mailed about it immediately. I start
tmuxwith a simple script which loops and calls
$ tmux new-session -d looper.shThe
looper.shscript looks roughly like:
t=`mktemp` while [ 1 ]; do supuner -e -o $t cmd || cat $t | mail -s "Error from cmd" firstname.lastname@example.org done