Skip to content

Instantly share code, notes, and snippets.

@Ropid
Created December 10, 2020 21:09
Show Gist options
  • Save Ropid/1234d3bdcb7558dee777c621f7f3e4a8 to your computer and use it in GitHub Desktop.
Save Ropid/1234d3bdcb7558dee777c621f7f3e4a8 to your computer and use it in GitHub Desktop.
Track system log for error messages and show desktop notifications (Linux, systemd-journal, libnotify)
#!/bin/bash
##
## Description:
## Track system log for error messages and show desktop notifications.
##
## filter messages that shouldn't show a notification
filter() {
grep --line-buffered -vE \
-e ': gkr-pam: unable to locate daemon control file$' \
-e ' pulseaudio\S+: ALSA woke us up to \S+ new data \S+ the device, but there was actually nothing to \S+.$' \
-e ' pulseaudio\S+: Most likely this is a bug in the ALSA driver .snd_hda_intel.. Please report this issue to the ALSA developers.$' \
-e ' pulseaudio\S+: We were woken up with POLL\S+ set -- however a subsequent snd_pcm_avail.. returned 0 or another value < min_avail.$' \
-e ' libvirtd\S+: internal error: End of file from qemu monitor$' \
###
}
## filter messages that should only show a 'normal' notification instead of 'critical'
not_critical() {
! grep -q -vE \
-e 'kernel: \[drm:amdgpu_gem_va_ioctl \[amdgpu\]\] \*ERROR\* Couldn.t update BO_VA \(-16\)$' \
###
}
#------------------------------------------------------------------------------
if pidof -o "$$" -x "$0" > /dev/null; then
echo "${0##*/}: An instance of this script is already running!"
exit 1
fi
journalctl -f -q -b -perr |
filter |
while read -r line; do
buffer="$line"
# collect a sequence of messages over one second into a single desktop notification
while read -t1 line; do
buffer="$buffer"$'\n'"$line"
done
# echo "-->"
# echo "$buffer"
# echo "<--"
if not_critical <<< "$buffer"; then
notify-send -t 7000 -i dialog-warning -u normal -- "Error!" "$buffer"
else
notify-send -t 0 -i dialog-error -u critical -- "Error!" "$buffer"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment