1
0
Fork 0

Script to send mail from systemd timers on failure

This commit is contained in:
Luca Beltrame 2020-07-20 00:04:07 +02:00
parent 9c2868feda
commit 20bbee7a56
Signed by: einar
GPG key ID: 4707F46E9EC72DEC

25
unit_mail.sh Executable file
View file

@ -0,0 +1,25 @@
#!/bin/bash
MAILTO="root"
MAILFROM="root@internal.heavensinferno.net"
UNIT=$1
EXTRA=""
for e in "${@:2}"; do
EXTRA+="$e"$'\n'
done
UNITSTATUS=$(systemctl status $UNIT)
sendmail $MAILTO <<EOF
From:$MAILFROM
To: $MAILTO
Subject:[systemd timer] Status mail for unit: $UNIT
Status report for unit: $UNIT
$EXTRA
$UNITSTATUS
EOF
echo -e "Status mail sent to: $MAILTO for unit: $UNIT"