#!/bin/bash set -u STATUS_OUT="$(systemctl status --full "$1" 2>/dev/null | head -n 30)" if [ -z "$STATUS_OUT" ]; then STATUS_OUT="(no matching systemd unit found for: $1)" fi /usr/bin/sendmail -t < Subject: $1 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 A problem with the service $1 occurred: $STATUS_OUT ERRMAIL