Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

3 Answers 3

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
r1=$?
make doc-all 1>/dev/null 2>> $LOG
r2=$?
cp doc/latex/refman.pdf doc/html/ 2>> $LOG
r3=$?

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
fi
share|improve this answer
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.