Last active
February 18, 2025 10:56
-
-
Save LevitatingBusinessMan/e33551bb56ad722e71eb7229ef0a3914 to your computer and use it in GitHub Desktop.
systemd service to email status of systemd services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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