How can I detect when a flash drive is connected to Linux?

How to determine when a flash drive is connected? I am using a clean Debian installation without any GUI and want to be notified in my Python script when a new flash drive appears ... I know that D-BUS distributes such information, but I do not want to use D-BUS. Is there more open access to this information? Should it be unavailable in / proc or / sys? How can I “connect” to this source?

Bye Falstaff

+5
source share
6 answers

You can read uevents from the kernel via Netlink and find the events where "ACTION"- "add"(you can also see if the partition was mounted or unmounted from the device, or if the device was removed). This is as close to the source of the events as possible in the user space. As far as I know, this is how it udevdetects inserted removable media.

But probably using the D-Bus / HAL API using Python bingings will be much easier (without parsing uuevents data, etc.). You don’t know why you are against it. Since you are using Python, I suspect that resources are not really a problem.

+6
source

Linux udev, .

+9

, mdev udev. mdev, script.

, script, mdev , . , , udev, .

+4

USB- syslog, /var/log/messages. "dmesg" . , , , /dev/sd (letter) (number) , .

+1

/proc/partition , .

0

, zenity script udev rhel6 :

KERNEL == "sd [b-d]", DRIVERS == "usb", ACTION == "add", RUN + = "/path/to/ script"

0

All Articles