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

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)

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.

  • 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. – Paused until further notice. 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
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
  • That's true, thanks, but i'd like to find something that does the job easier :) – kolypto Jul 25 '09 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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