I want to see smartd notifications in DE (Gnome3). So I've configured smartd to execute custom script that uses notify-send to notify all logged users:
smartd.conf:
/dev/sda -m root -M test -M exec /etc/smartmontools/smartd_warning.d/notify -a -n standby,10,q
smartd_warning.d/notify:
#!/usr/bin/env sh
IFS=$'\n'
for LINE in `w -hs`
do
USER=`echo $LINE | awk '{print $1}'`
USER_ID=`id -u $USER`
DISP_ID=`echo $LINE | awk '{print $8}'`
sudo -u $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
done
it works correctly only if I restart smartd when I logged into system. Obviously it can't work on boot, because smartd starts before any user logged into system.
[Unit]
Description=Self Monitoring and Reporting Technology (SMART) Daemon
Documentation=man:smartd(8) man:smartd.conf(5)
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/smartmontools
ExecStart=/usr/sbin/smartd -n $smartd_opts
ExecReload=/bin/kill -HUP $MAINPID
StandardOutput=syslog
[Install]
WantedBy=multi-user.target
How can bind smartd service to user session to see those notifications?