1#!/bin/bash
2
3# Email logs of failed e2scrub unit runs when the systemd service fails.
4
5recipient="$1"
6test -z "${recipient}" && exit 0
7device="$2"
8test -z "${device}" && exit 0
9hostname="$(hostname -f 2>/dev/null)"
10test -z "${hostname}" && hostname="${HOSTNAME}"
11if ! type sendmail > /dev/null 2>&1; then
12	echo "$0: sendmail program not found."
13	exit 1
14fi
15
16(cat << ENDL
17To: $1
18From: <e2scrub@${hostname}>
19Subject: e2scrub failure on ${device}
20
21So sorry, the automatic e2scrub of ${device} on ${hostname} failed.
22
23A log of what happened follows:
24ENDL
25systemctl status --full --lines 4294967295 "e2scrub@${device}") | sendmail -t -i
26