0

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 :)

kolypto
  • 11,058
  • 12
  • 54
  • 66

3 Answers3

5

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.

David Pashley
  • 23,497
  • 2
  • 46
  • 73
  • 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 04: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 05:21
4

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 +x /usr/local/bin/delaystderr, 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)

Ingo Karkat
  • 232
  • 5
  • 10
womble
  • 96,255
  • 29
  • 175
  • 230
1

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
Gary Chambers
  • 725
  • 4
  • 8