Mail report without cron?

As I have a bunch of other scripts in my cron, I don’t want to have them mailed as well. So, I’m wondering how I can get the report of restic mailed to me? Piping the output to a text-file and mail that? Any pointers?

i just did this for a different command. This is not fully tested but i should point you in the right direction

NOW=$( date '+%Y-%m-%d-%H-%M-%S' )
yourrestic-command | /usr/bin/tee -a logfile-$now
mail -s "restic-comand finished " you@yourdomain.com < logfile-$now
1 Like

There’s the cronutils package, which contains a few helpful programs: https://github.com/google/cronutils

And then there’s the program collection in the Debian package moreutils, which contains the program chronic:

chronic runs a command, and arranges for its standard out and standard error to only be displayed if the command fails (exits nonzero or crashes). If the command succeeds, any extraneous output will be hidden.

I often use mailx with the -E option, like this:

some_command | mailx -E -s backup root@domain.tld

It’ll send an email to root@domain.tld with the output from the command, and -E instructs mailx to not send a mail when the body is empty. Very helpful :slight_smile:

I have chosen my approach because it allows you to define which parts of a sheduled bash script you want to recieve via mail. I often have scripts that produce a ton of output which I dont want to see.

via “tee -a” I can select which commands of a bash script I want to be part of the report.

I could Imagine for example you define that you only want to get the last X lines of a restic forget command.

Thanks for the commands - both are working fine, so I’m quite happy with the solution. Love Restic btw! :slight_smile:

PS. When is compression coming :wink: