smartd-notify-all 690 B

12345678910111213141516171819
  1. #!/usr/bin/env bash
  2. # Notify all users on S.M.A.R.T errors
  3. # Place in /usr/share/smartmontools/smartd_warning.d/ or use "DEVICESCAN -m @smartd-notify-all" in /etc/smartd.conf
  4. # Copyright 2021 Bryan C. Roessler
  5. parent="${BASH_SOURCE[0]}"
  6. parent=${parent%/*}
  7. [[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
  8. is_root
  9. IFS=$'\n'
  10. for LINE in $(w -hs); do
  11. USER=$(echo "$LINE" | awk '{print $1}')
  12. USER_ID=$(id -u "$USER")
  13. DISP_ID=$(echo "$LINE" | awk '{print $8}')
  14. sudo su "$USER" DISPLAY="$DISP_ID" DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/"$USER_ID"/bus notify-send "S.M.A.R.T Error ($SMARTD_FAILTYPE) $SMARTD_MESSAGE" --icon=dialog-warning
  15. done