Skip to content

Instantly share code, notes, and snippets.

@benediktg
Last active December 1, 2023 10:11
Show Gist options
  • Save benediktg/7f3996491bb989d1c84f03ff6038deb2 to your computer and use it in GitHub Desktop.
Save benediktg/7f3996491bb989d1c84f03ff6038deb2 to your computer and use it in GitHub Desktop.
Send mails from systemd services
[Unit]
Description=Status email for %i to user
[Service]
Type=oneshot
ExecStart=/usr/local/bin/systemd-email mail@example.org %i
User=nobody
Group=systemd-journal
#!/bin/bash
set -eu
# sendmail is in /usr/sbin on openSUSE
/usr/sbin/sendmail -t <<ERRMAIL
To: ${1}
From: systemd <root@${HOSTNAME}>
Subject: ${2}
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
$(systemctl status --full "$2")
ERRMAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment