0

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?

1

You could try changing your WantedBy to graphical.target or default.target according to this.

Short explanation; multi-user.target means the system is up but it does not mean a user is logged on, graphical.target implies a local user login, and default.target is a common alias for graphical.target but might be aliased to other values as well.

Also, if you want to simply ensure you are not missing any notifications you could echo the same data you are sending via notify-send to a file as well. Which should be something like:
echo "S.M.A.R.T Error ($SMARTD_FAILTYPE)" "$SMARTD_MESSAGE" >> /"YourPathHere"/smartd.log
(Be sure to use a path that your script can write to though)

1
  • I"ve tried and it's not working. The reason is that you can send a message via DBus to any user only when he's actually logged into system (see w -hs command). There's no any queue. Your second suggestion seems reasonable, I've thought about that too, but I'd like to see notification, and to do so I'd have to parse and clear such log manually. In that case keeping each message as separate file looks more simple to manage (../smartlog/*.msg). Right... it looks like I reinvent the email. – Evan Jun 14 '20 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.