0

I have written a udev rule that call a script to send email when a usb drive is attached/removed. so far its working fine. following is my udev rule and send email script:

SUBSYSTEM=="usb", ACTION=="add", RUN+="/u/usb_added %b"
SUBSYSTEM=="usb", ACTION=="remove", RUN+="/u/usb_removed %b"

But in sendemail script i also want to include detail of usb drive (usb size, label, mounted on and time of attachment). But I dont know how to get this information. can anyone please help me either from udev or to write a script in bash to read log/messages and fetch this information.

user115079
  • 711
  • 1
  • 11
  • 23

1 Answers1

0

You an use the udevmonitor tool to get the environment variables that the uevent emitted. From these information, you can locate where your block device locates under /sys/ and get further information. You can also use blkid tool to get the information with the DEVNAME exported by uevent.

Dien Nguyen
  • 2,019
  • 6
  • 30
  • 37
  • But isn't this only helpful when the device is attached. That advice doesn't seem to work when the device is removed. – FlexMcMurphy May 11 '22 at 22:14