[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tarsnap fails with broken pipe in systemd timer unit

On 2019-10-08 09:53, Simon Levermann wrote:
> /usr/bin/tarsnap --list-archives | /bin/grep -q ${current_date}
> [...]
> Okt 08 18:45:27 slevermann.de tarsnap.sh[17247]: tarsnap: fprintf: Broken pipe
> Okt 08 18:45:27 slevermann.de tarsnap.sh[17247]: tarsnap: Error listing archives

The `grep -q` command exits as soon as it finds a matching line, breaking
the pipe which tarsnap's output is directed to.  Most programs exit silently
when this happens; tarsnap is paranoid and prints a warning before exiting
with a failure status.

Why your shell cares about tarsnap's exit code, I don't know; normal POSIX
shells ignore the exit codes from processes other than the last one in a
pipeline.  Maybe systemd launches bash with some weird "don't behave the way
that shells are supposed to behave" flags.

You can probably get what you want by replacing the above line with

( /usr/bin/tarsnap --list-archives 2>/dev/null || true ) | \
    /bin/grep -q ${current_date}

since that will silence the warnings and ignore the exit code.

Colin Percival
Security Officer Emeritus, FreeBSD | The power to serve
Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid