LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   How to use udev to detect when any SD card is plugged into a usb adaptor. (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/how-to-use-udev-to-detect-when-any-sd-card-is-plugged-into-a-usb-adaptor-4175509690/)

CaptainMark 06-30-2014 05:22 PM

How to use udev to detect when any SD card is plugged into a usb adaptor.
 
I would like to have a script run whenever I plug any SD card into a specific SD adaptor, I've been told that udev is the way to go but I'm at a complete loss, I've done some searching and can find plenty of information that relates to running scripts when a specific drive is plugged in but not anything about any cards plugged into a specific adaptor/hub.

I've only managed to get so far that the hub itself has an entry in the output of lsusb which is
Code:

Bus 001 Device 011: ID 0bda:0119 Realtek Semiconductor Corp.
After that I'm lost completely, all the guides assume you know which /dev/sd? entry you're looking for, which I don't

Additionally if I remove and then reconnect the adaptor this is the output written to /var/log/messages
Code:

Jun 30 22:22:57 raspberrypi kernel: [ 2114.145106] usb 1-1.3.4.2: USB disconnect, device number 11
Jun 30 22:23:00 raspberrypi kernel: [ 2116.427548] usb 1-1.3.4.2: new high-speed USB device number 12 using dwc_otg
Jun 30 22:23:00 raspberrypi kernel: [ 2116.534769] usb 1-1.3.4.2: New USB device found, idVendor=0bda, idProduct=0119
Jun 30 22:23:00 raspberrypi kernel: [ 2116.534808] usb 1-1.3.4.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 30 22:23:00 raspberrypi kernel: [ 2116.534826] usb 1-1.3.4.2: Product: USB2.0-CRW
Jun 30 22:23:00 raspberrypi kernel: [ 2116.534839] usb 1-1.3.4.2: Manufacturer: Generic
Jun 30 22:23:00 raspberrypi kernel: [ 2116.534852] usb 1-1.3.4.2: SerialNumber: 20090815198100000
Jun 30 22:23:00 raspberrypi kernel: [ 2116.540723] usb-storage 1-1.3.4.2:1.0: USB Mass Storage device detected
Jun 30 22:23:00 raspberrypi kernel: [ 2116.543236] scsi6 : usb-storage 1-1.3.4.2:1.0
Jun 30 22:23:01 raspberrypi kernel: [ 2117.540126] scsi 6:0:0:0: Direct-Access    Generic- SD/MMC          1.00 PQ: 0 ANSI: 0 CCS
Jun 30 22:23:01 raspberrypi kernel: [ 2117.542785] sd 6:0:0:0: Attached scsi generic sg3 type 0
Jun 30 22:23:01 raspberrypi kernel: [ 2117.548659] sd 6:0:0:0: [sdb] Attached SCSI removable disk

I'm running up to date Raspian (debian) on a raspberry pi,

Can someone point me in the right direction at least?

Many Thanks for your help

Mark

littlejoe5 07-04-2014 07:49 PM

I'm having a similar problem. maybe this can help.
 
I'm using Debian derivatives, and don't know if others are the same.

Most (maybe all) USB thumb drives, and/or USB adapters with sd chips in them will register in /media with an automatic name which is the block ID for that unit. With Thumb drives, or sd chips, that is two two segments of four digits each separated by a dash. (For instance /media/86C8-2CBD).

I want to be able to record identical (or dis-similar) programs onto 10 or more chips, as quickly as possible, and (in case one fails, or is two slow), to be able with certainty to know which one it is without testing each one.

Maybe my observations can help you.


All times are GMT -5. The time now is 09:10 AM.