Is there a way to display errors summary (from stderr) after an application has finished?

E.g. rsync with "--progress" displays LOTS of data, including errors. But when it finishes - it just says "there were errors". I want to display everything that was written to stderr in that case, so i don't have to scroll and search what precisely went wrong :)

P.S. I know how simple it is to write such utility in C, but i guess there can be more handy things i'm not aware of :)

link|improve this question

feedback

3 Answers

up vote 4 down vote accepted

A wrapper script to handle this:

#!/bin/sh

TMPFILE=$(mktemp)

"$@" 2>$TMPFILE

if [ "$?" != "0" ]; then
  cat $TMPFILE
fi

If you save this to /usr/local/bin/delaystderr and chmod, you should be able to run as delaystderr rsync --progress. If the process exits without signalling error (returning non-zero), stderr won't be printed; you can delete the lines starting with if and fi` to disable that behaviour if you like.

I'm not sure how you'd get any easier than that.

(Note: I haven't actually tested this script, so buyer beware and all that)

link|improve this answer
feedback

Similar to womble's answer, you can write a bash script something like:

#!/bin/sh

set -e

TMPFILE=$(mktemp)

exec 2>$TMPFILE
trap 'cat "$TMPFILE"; rm -f "$TMPFILE" exit $?' INT TERM EXIT

command1
command2
command3

and this should save everything sent to stderr for the entire script and output it at the end. As with womble's answer, I've not tested this.

link|improve this answer
I don't know how many errors Gary is getting but if it's a lot then "easier" might mean that cat should be replaced by more or less. – Dennis Williamson Jul 25 '09 at 4:17
less in a script is annoying. If you want to page the output, pipe the script into less. It's more flexible that way. – David Pashley Jul 25 '09 at 5:21
feedback

If you're using bash redirect stderr to stdout then, optionally, redirect that to a file:

rsync --progress 2>&1
rsync --progress 2>&1 > file.out
link|improve this answer
That's true, thanks, but i'd like to find something that does the job easier :) – o_O Tync Jul 25 '09 at 2:36
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.