You are not logged in.
I'd like to automatically check SMART for errors every time external USB drives are connected, and show a popup if needed. What would be the best way to do it?
I've tried to configure smartd as specified at https://wiki.archlinux.org/index.php/S.M.A.R.T.#smartd (including the notify-send script) but I'm not sure it's doing what I want.
Would it be possible to do that using udev rules + smartctl?
Thanks
Last edited by midian (2020-09-27 11:37:12)
Offline
SMART support must be available and enabled on each storage device to effectively use these tools. You can use #smartctl to check for and enable SMART support
You did try with an external drive that supports smart and has it enabled ?
If you run the smartdnotify script manually, does it show a notification ?
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
(A works at time B) && (time C > time B ) ≠ (A works at time C)
Offline
Instead smartd daemon, I would suggest a udev rule to detect the usb drive and then hand over to a systemd type=oneshot service to run smartctl and notify-send.
something like this:
$ cat 99-usb.rules
ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", SUBSYSTEMS=="usb",
ATTRS{idVendor}=="AAAA", ATTRS{idProduct}=="BBBB", ENV{SYSTEMD_WANTS}+="usb.service"
$ cat usb.service
Description=USB smart and notify Daemon
[Service]
Type=oneshot
TimeoutStartSec=300
ExecStart=/usr/local/bin/usb.sh
[Install]
WantedBy=multi-user.target
$ cat /usr/local/bin/usb.sh
# smartclt -c /dev/sdX
# nofity-send
...
Last edited by solskog (2020-09-25 11:43:42)
Offline
@Lone_Wolf running the script manually from the terminal doesn't show anything (I replaced the username and userid with the user running gnome, not sure if the script is compatible with wayland)
@solskog it seems just what I had in mind, thanks. I'll have to find a way to make it use the device name of the connected usb drive instead of the hardcoded sdX though.
Last edited by midian (2020-09-25 12:05:55)
Offline
I'll have to find a way to make it use the device name of the connected usb drive instead of the hardcoded sdX though.
Well, the device name can be referred by $env{DEVNAME} in udev rule and passed to systemd unit template file as argument.
$ cat 99-usb.rules
ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", SUBSYSTEMS=="usb", ENV{DEVTYPE}=="disk", ATTRS{idVendor}=="AAAA", ATTRS{idProduct}=="BBBB", PROGRAM="/bin/systemd-escape -p --template=usb@.service $env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"
$ cat usb@.service
Description=USB smart and notify Daemon
[Service]
Type=oneshot
TimeoutStartSec=300
ExecStart=/usr/local/bin/usb.sh %I
[Install]
WantedBy=multi-user.target
Last edited by solskog (2020-09-27 03:44:59)
Offline
Well, the device name can be referred by $env{DEVNAME} in udev rule and passed to systemd unit template file as argument.
Ah, thanks!
Offline