Sample Header Ad - 728x90

Udev rules, need to obtain path like /dev/sda

0 votes
1 answer
3758 views
I try to get the path of the last connected disk via an environment variable, i.e. a path like /dev/sd*. The problem is that DEVNAME or DEVPATH does not provide the desired path. The goal is to make echo $...... > /var/..... once the value is stored, and execute differents actions with RUN +=... I get it out when I need it. I hope I was clear in my explanations, thank you I'm trying to get the path of the current disk, in this case /dev/sd*. I use udev rules to execute an action SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", RUN+="/bin/device_added.sh" SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", RUN+="/bin/device_removed.sh" The problem is that when I retrieve with echo $KERNEL > my-file, I can't find the path of the current disk. I need this variable to execute smartctl commands from the disk that just arrived. In device_added.sh the goal is to launch the smartctl -a /dev/sd* command except that we replace /dev/sd* by the last connected disk, so here is my problem now, I need to recover the path of the last connected disk/detected by udev rules.
Asked by AnonymousREQUEST (1 rep)
May 5, 2022, 08:29 AM
Last activity: Jun 27, 2025, 06:01 PM