Created
May 3, 2025 12:25
-
-
Save p0358/fb93e218e910f66a1d5d59ce5dd08f37 to your computer and use it in GitHub Desktop.
Get desktop notifications about apcupsd events on Linux (like you would on Windows with the tray app)
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
# ~/.config/systemd/user/apcupsd-notify.service | |
# $ systemctl --user daemon-reload | |
# $ systemctl --user enable --now apcupsd-notify | |
[Unit] | |
Description=apcupsd notify | |
ConditionPathExists=/var/log/apcupsd.events | |
[Service] | |
Type=simple | |
ExecStart=%h/bin/apcupsd-notify.sh | |
Restart=always | |
[Install] | |
WantedBy=graphical-session.target |
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
#!/bin/bash | |
f="/var/log/apcupsd.events" | |
curr=$(<"$f") | |
inotifywait -m -e modify "$f" --format "%e" | while read -r event; do | |
if [ "$event" == "MODIFY" ]; then | |
prev="$curr" | |
curr=$(<"$f") | |
[ "$curr" == "$prev" ] || notify-send -u critical -a apcupsd "${curr##*$'\n'}" && echo "${curr##*$'\n'}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment