1*6a54128fSAndroid Build Coastguard Worker#!/bin/bash 2*6a54128fSAndroid Build Coastguard Worker 3*6a54128fSAndroid Build Coastguard Worker# Email logs of failed e2scrub unit runs when the systemd service fails. 4*6a54128fSAndroid Build Coastguard Worker 5*6a54128fSAndroid Build Coastguard Workerdevice="$1" 6*6a54128fSAndroid Build Coastguard Workertest -z "${device}" && exit 0 7*6a54128fSAndroid Build Coastguard Worker 8*6a54128fSAndroid Build Coastguard Workerif ! type sendmail > /dev/null 2>&1; then 9*6a54128fSAndroid Build Coastguard Worker echo "$0: sendmail program not found." 10*6a54128fSAndroid Build Coastguard Worker exit 1 11*6a54128fSAndroid Build Coastguard Workerfi 12*6a54128fSAndroid Build Coastguard Worker 13*6a54128fSAndroid Build Coastguard Workerif test -f /etc/e2scrub.conf ; then 14*6a54128fSAndroid Build Coastguard Worker . /etc/e2scrub.conf 15*6a54128fSAndroid Build Coastguard Workerfi 16*6a54128fSAndroid Build Coastguard Worker 17*6a54128fSAndroid Build Coastguard Workerhostname="$(hostname -f 2>/dev/null)" 18*6a54128fSAndroid Build Coastguard Workertest -z "${hostname}" && hostname="${HOSTNAME}" 19*6a54128fSAndroid Build Coastguard Workerservice_name="e2scrub@$(systemd-escape ${device})" 20*6a54128fSAndroid Build Coastguard Worker 21*6a54128fSAndroid Build Coastguard Workerif test -z "${recipient}" ; then 22*6a54128fSAndroid Build Coastguard Worker recipient="root" 23*6a54128fSAndroid Build Coastguard Workerfi 24*6a54128fSAndroid Build Coastguard Worker 25*6a54128fSAndroid Build Coastguard Workerif test -z "${sender}" ; then 26*6a54128fSAndroid Build Coastguard Worker sender="<e2scrub@${hostname}>" 27*6a54128fSAndroid Build Coastguard Workerfi 28*6a54128fSAndroid Build Coastguard Worker 29*6a54128fSAndroid Build Coastguard Worker(cat << ENDL 30*6a54128fSAndroid Build Coastguard WorkerTo: ${recipient} 31*6a54128fSAndroid Build Coastguard WorkerFrom: ${sender} 32*6a54128fSAndroid Build Coastguard WorkerSubject: e2scrub failure on ${device} 33*6a54128fSAndroid Build Coastguard Worker 34*6a54128fSAndroid Build Coastguard WorkerSo sorry, the automatic e2scrub of ${device} on ${hostname} failed. 35*6a54128fSAndroid Build Coastguard Worker 36*6a54128fSAndroid Build Coastguard WorkerA log of what happened follows: 37*6a54128fSAndroid Build Coastguard WorkerENDL 38*6a54128fSAndroid Build Coastguard Workersystemctl status --full --lines 4294967295 "${service_name}") | sendmail -t -i 39