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
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.
"ACTION"
"add"
udev
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.
Linux udev, .
, mdev udev. mdev, script.
, script, mdev , . , , udev, .
USB- syslog, /var/log/messages. "dmesg" . , , , /dev/sd (letter) (number) , .
/proc/partition , .
, zenity script udev rhel6 :
KERNEL == "sd [b-d]", DRIVERS == "usb", ACTION == "add", RUN + = "/path/to/ script"