1

I use tarsnapper's make command for managing tarsnap backups like this:

tarsnapper -c /usr/local/etc/tarsnapper.conf make

Which works like it should and I get an output like this

Creating backup mail: mybackupjob-20150610-092951
3 backups are matching
0 of those can be deleted

I'm now running this in cron like so (cron seems to be running in /bin/sh on Ubuntu 15.04)

0 2 * * * PATH=$PATH:/usr/local/bin tarsnapper -c /usr/local/etc/tarsnapper.conf make >/dev/null

Which works otherwise but for some reason I still get the output (stdout) in my email by cron so the stdout redirection to /dev/null doesn't seem to work as needed.

I tried debugging by just running the command without cron using the redirection and still I get the output when running:

tarsnapper -c /usr/local/etc/tarsnapper.conf make >/dev/null

So how can I properly redirect the normal output (stdout) of this tarsnapper invocation to /dev/null?

I never had this kind of problem using >/dev/null redirection with other commands, so it must be something to do with how tarsnapper works, right?

I know that tarsnapper is a python script that calls the tarsnap binary.

I tried searching for answers about redirecting stdout but couldn't find anything that would solve my problem.

1 Answer 1

1

Damn, just after I posted my question I figured out the problem (after trying to find an answer for about an hour or two).

It would seem that tarsnapper just outputs all of its normal output to stderr instead of stdout. I think this is a bug in tarsnapper.

But to answer my own question I just need to redirect using 2>/dev/null instead (to rediredt stderr) to get rid of the "normal output" but I guess then I won't get any output even if there are possibly actual errors (which I would still like to get in my email from cron, if errors happen).

Edit:

As a temporary "solution" I ended up just redirecting all output (stdout and stderr) from tarsnapper appending it to a logfile using this in cron:

0 2 * * * PATH=$PATH:/usr/local/bin tarsnapper -c /usr/local/etc/tarsnapper.conf make >>/var/log/tarsnapper-cron.log 2>&1

So I can just check /var/log/tarsnapper-cron.log if I want to see how's tarsnapper been working without it spamming my email via cron.

It would obviously be better if I could also get possible errors to my email automatically, but currently that doesn't seem to be possible without modifying tarsnapper itself or making a script that parses the output of tarsnapper and tries to figure out if there is an error or not based on the output text.

3
  • I filed this as a bug at GitHub: github.com/miracle2k/tarsnapper/issues/26
    – Haprog
    Jun 10, 2015 at 10:24
  • You'll also get an email from cron if the command returns a nonzero status. If tarsnapper is so broken as to return 0 on errors, you might try something like grep Error tarsnapper-cron.log or ! grep Success tarsnapper-cron.log Jun 10, 2015 at 20:40
  • @Gilles Thanks, I didn't realize cron emails on non-zero exit status even without any output. Well then my current workaround is acceptable as I can check the saved log if I get an email about an error even if the email doesn't contain the error. Though I'm not sure if tarsnapper actually uses a non-zero exit status on error. I'll have to check that at some point.
    – Haprog
    Jun 11, 2015 at 6:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .