Skip to content

Instantly share code, notes, and snippets.

@LevitatingBusinessMan
Last active February 18, 2025 10:56
Show Gist options
  • Save LevitatingBusinessMan/e33551bb56ad722e71eb7229ef0a3914 to your computer and use it in GitHub Desktop.
Save LevitatingBusinessMan/e33551bb56ad722e71eb7229ef0a3914 to your computer and use it in GitHub Desktop.
systemd service to email status of systemd services
#!/usr/bin/env fish
if test (count $argv) -lt 1
echo "Usage: $(status --current-filename) <systemd unit>"
exit 1
end
set sstatus (systemctl --full --lines 0 status $argv[1] | string collect); or exit
set log (journalctl -b -n 50 -u $argv[1] | string collect); or exit
if systemctl -q is-failed $argv[1]
set prefix Failed
else
set prefix Status of
end
set message "\
Subject: $prefix systemd service on $(hostname): $argv[1]
Content-Type: text/plain; charset=UTF-8
$sstatus
$log
"
echo $message | sendmail root
[Unit]
Description=Send an email with the status of %i
[Service]
Type=oneshot
ExecStart=/usr/local/libexec/systemd-status-notify.fish %i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment