Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There exists a Git repo that is on one server, we want to generate doxygen output for it on a different server. The following command works for me but has the downside of sending a mail everytime the repo is updated because Git uses stderr for progress reporting (a quick search via the almighty oracle suggests they consider this behaviour a feature).

59 * * * * cd FQNameOfRepo; git pull 1>/dev/null; make doc-all 1>/dev/null; cp doc/latex/refman.pdf doc/html/

While I could grep through the stderr output of Git or compare it to a known string this seems wrong. Am I using the wrong Git command? How would this be done properly?

For clarification I still want this command to send a mail if a real error occurs, so simply redirecting stderr won't help.

share|improve this question
up vote 1 down vote accepted

Relying on the mailing capabilities of crond too much may yield various problems. Depending on your your crond they are perhaps just not flexible enough.

For example, often, as you described, one cannot configure that only an exit status != 0 should trigger the mailing of stdout/stderr. Another issue is that, for example, the Solaris crond has a (relatively) small size limit on the output it captures/mails.

Thus, for such situations, I suggest writing a small helper script that calls the commands and redirects the output to a temporary log-file. It can internally keep track of the exit status of all the programs and if one is != 0 it either:

  • cat the log-file to stdout
  • mail it via a command line mail tool
  • or just output short diagnostics that include the location of the log-file

Something like:

$ cat helper.sh
set -u
set -e

# setup log-file $LOG
# ...

cd FQNameOfRepo
set +e

git pull 1>/dev/null 2>> $LOG
make doc-all 1>/dev/null 2>> $LOG
cp doc/latex/refman.pdf doc/html/ 2>> $LOG

set -e

if [ $r1 -ne 0 -o $r2 -ne 0 -o $r3 -ne 0 ]; then
    # do some stuff, print/mail $LOG or something like that, etc.
    # ...
    exit 23
share|improve this answer

Store the output in a variable or a temporary file, and print it only if the return status is nonzero.

59 * * * * errors=$( { cd FQNameOfRepo && git pull && make doc-all && cp doc/latex/refman.pdf doc/html/; } 2>&1 >/dev/null) || { ret=$?; echo "$errors"; exit $ret; }

(You may want to put this rather long one-liner in a script.)

share|improve this answer

You could use rsyslog. It has a mail output module. Set up a filter module that traps the especific error from the git repository and route it to the mail destination(s).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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