You are not logged in.

#1 2020-09-25 06:11:46

midian
Member
Registered: 2019-02-21
Posts: 39

[solved] Automatically warn about failing usb drives?

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

#2 2020-09-25 10:28:04

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

Re: [solved] Automatically warn about failing usb drives?

https://wiki.archlinux.org/index.php/S.M.A.R.T.#Smartmontools wrote:

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

#3 2020-09-25 11:42:40

solskog
Member
Registered: 2020-09-05
Posts: 416

Re: [solved] Automatically warn about failing usb drives?

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

#4 2020-09-25 12:03:55

midian
Member
Registered: 2019-02-21
Posts: 39

Re: [solved] Automatically warn about failing usb drives?

@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

#5 2020-09-27 03:36:32

solskog
Member
Registered: 2020-09-05
Posts: 416

Re: [solved] Automatically warn about failing usb drives?

midian wrote:

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

#6 2020-09-27 11:36:40

midian
Member
Registered: 2019-02-21
Posts: 39

Re: [solved] Automatically warn about failing usb drives?

solskog wrote:

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

Board footer

Powered by FluxBB