LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-14-2007, 03:25 AM   #16
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,517

Rep: Reputation: 90

I tried further out of curiosity and got a similar setup working. It's a USB harddisk, not a memory card, but it is the same way regarded as scsi device by my system.

Changes I did were:

/etc/udev/10-local.rules -- creates a consistent symlink for my hd (usbhd-trekstor1 is the only partition on it). Full path to script as well as to the calling shell!
Code:
BUS=="scsi", KERNEL=="sd*",  ACTION=="add", SYSFS{model}=="HD400LD         ", SYSFS{vendor}=="SAMSUNG ", NAME="%k", SYMLINK="usbhd-trekstor%n", RUN+="/bin/sh /etc/udev/scripts/trekstor.sh"
/etc/udev/scripts/trekstor.sh -- the folder didn't exist, but I liked to put the script somewhere near my rules. I'm not sure if the sleep and sync commands are necessary, but they won't harm anyway. I could not get any GUI message working using Xdialog, so I created a logfile that will contain all mount/cp/umount successes. No error checking here, but it works. Changed the script to executable (chmod +x /etc/udev/scripts/trekstor.sh).
Code:
#!/bin/sh
export LOGFILE="/var/log/trekstor.log"

sleep 10
/sbin/mount /dev/usbhd-trekstor1 /mnt/usbhd-trekstor1 && echo "successly mounted trekstor at $(date)" >> $LOGFILE
touch /var/log/trekstor.log
cp "/mnt/data/video/fertig-archiv/Higgins - OSullivan _ WM 2007 Viertelfinale.avi" /mnt/usbhd-trekstor1/Snooker/ && echo "done copying files at $(date)" >> $LOGFILE
sleep 5
/bin/sync
/sbin/umount /mnt/usbhd-trekstor1 && echo "successfully unmounted trekstor at $(date)" >> $LOGFILE
Restarted udev, switched on my external harddisk and -- voilą!

EDIT: Of course this might be broken in another environment. Slackware 11, kernel 2.7.17.13, udev version 097

Last edited by titopoquito; 05-14-2007 at 03:32 AM.
 
Old 05-14-2007, 01:15 PM   #17
PlancksCnst
Member
 
Registered: Sep 2006
Posts: 34

Original Poster
Rep: Reputation: 15
Success! (mostly)

Adding the path to bash worked, but I don't understand why - none of the other script calls in the rules have that. Now that it's at least getting the files over to the card, I looked up how to use rsync. So now instead of cp, I used rsync, which is much better. I also match on the serial # now, so it will work only for this memory card.

The only problem now is that it's executing the script 10 or 20 times every time I insert it.
 
Old 05-14-2007, 02:30 PM   #18
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,517

Rep: Reputation: 90
Maybe cut out the "ADD" part to see what happens. At least here the script executed well without that. And it executed only once
 
Old 05-15-2007, 06:44 PM   #19
PlancksCnst
Member
 
Registered: Sep 2006
Posts: 34

Original Poster
Rep: Reputation: 15
So, I finally got it - still not perfect, but it works for now.
It was executing the script multiple times because of some kind of device hierarchy that I don't quite get yet. If you do a udevinfo on a device you'll see information for that device, and it's parent device, and it's parent's parent device, and so on, all the way up to the actual pci bus. Well, the model name for my device shows up a couple layers up. The serial number for the device shows up in an even higher layer. I tried matching on that instead of the model. It executed the script even more times. So I tried matching on an attribute on the "lowest" device which showed up in the udevinfo. It worked - the script was only executed once each time I inserted the card. So, apparently, it's executing the rule some number of times for each of these layers. Pretty weird. I wonder if it just has something to do with the way my distro (Zenwalk) is set up. I'll eventually get around to testing this on my Gentoo system, which hopefully will be more straightforward.

The remaining problem is now that I'm matching on a rather general attribute - the size. This is because there isn't anything more specific than that for that lowest-level device. If I add anything else with the same size, it will probably run this rule.

Here is the udevinfo for the device if it makes things any clearer.
Code:
  looking at device '/block/sdb':
    KERNEL=="sdb"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{stat}=="      86      278      567      692        0        0        0        0        0      580      692"
    ATTR{size}=="1956864"
    ATTR{removable}=="1"
    ATTR{range}=="16"
    ATTR{dev}=="8:16"

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/usb1/1-2/1-2:1.0/host21/target21:0:0/21:0:0:0':
    KERNELS=="21:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{ioerr_cnt}=="0x2"
    ATTRS{iodone_cnt}=="0x66"
    ATTRS{iorequest_cnt}=="0x66"
    ATTRS{iocounterbits}=="32"
    ATTRS{timeout}=="30"
    ATTRS{state}=="running"
    ATTRS{rev}=="1.00"
    ATTRS{model}=="Flash Reader    "
    ATTRS{vendor}=="Multi   "
    ATTRS{scsi_level}=="3"
    ATTRS{type}=="0"
    ATTRS{queue_type}=="none"
    ATTRS{queue_depth}=="1"
    ATTRS{device_blocked}=="0"
    ATTRS{max_sectors}=="240"

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/usb1/1-2/1-2:1.0/host21/target21:0:0':
    KERNELS=="target21:0:0"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/usb1/1-2/1-2:1.0/host21':
    KERNELS=="host21"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/usb1/1-2/1-2:1.0':
    KERNELS=="1-2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb-storage"
    ATTRS{modalias}=="usb:v058Fp6331d0102dc00dsc00dp00ic08isc06ip50"
    ATTRS{bInterfaceProtocol}=="50"
    ATTRS{bInterfaceSubClass}=="06"
    ATTRS{bInterfaceClass}=="08"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/usb1/1-2':
    KERNELS=="1-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{serial}=="058F0O1111B"
    ATTRS{product}=="Mass Storage Device"
    ATTRS{manufacturer}=="Generic"
    ATTRS{maxchild}=="0"
    ATTRS{version}==" 2.00"
    ATTRS{devnum}=="21"
    ATTRS{speed}=="12"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bcdDevice}=="0102"
    ATTRS{idProduct}=="6331"
    ATTRS{idVendor}=="058f"
    ATTRS{bMaxPower}=="250mA"
    ATTRS{bmAttributes}=="80"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{configuration}==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{serial}=="0000:00:1f.2"
    ATTRS{product}=="UHCI Host Controller"
    ATTRS{manufacturer}=="Linux 2.6.20 uhci_hcd"
    ATTRS{maxchild}=="2"
    ATTRS{version}==" 1.10"
    ATTRS{devnum}=="1"
    ATTRS{speed}=="12"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bcdDevice}=="0206"
    ATTRS{idProduct}=="0000"
    ATTRS{idVendor}=="0000"
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{configuration}==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2':
    KERNELS=="0000:00:1f.2"
    SUBSYSTEMS=="pci"
    DRIVERS=="uhci_hcd"
    ATTRS{msi_bus}==""
    ATTRS{broken_parity_status}=="0"
    ATTRS{enable}=="1"
    ATTRS{modalias}=="pci:v00008086d00002442sv00001179sd0000FF00bc0Csc03i00"
    ATTRS{local_cpus}=="f"
    ATTRS{irq}=="5"
    ATTRS{class}=="0x0c0300"
    ATTRS{subsystem_device}=="0xff00"
    ATTRS{subsystem_vendor}=="0x1179"
    ATTRS{device}=="0x2442"
    ATTRS{vendor}=="0x8086"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't run openoffice from bash-script with udev krisealv Programming 1 04-16-2007 11:17 AM
udev does not run program on remove uselpa Slackware 2 10-22-2006 04:24 AM
usb won't work with udev dinolinux Linux - Software 4 06-14-2006 10:21 AM
udev rules all_partitions doesn't work arubin Slackware 1 06-10-2006 05:46 PM
Making UDEV Work dannyl Slackware 42 01-29-2006 12:20 AM


All times are GMT -5. The time now is 11:51 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration