0

I need to run a script, when connecting a usb-drive to an embedded system. My idea was:

SUBSYSTEM=="block",ACTION=="add", KERNELS=="sd?",RUN+="/script param1 %k"

It needs to run with any usb-stick, so I am not able to use Vendor-specific parameters. Now the script executes with sd[a..][,1..], but it should only execute when sd[a..] connects (_ for NULL). With the ? it works when disconnecting, but on connecting, it executes for each partition Is there any possibility or do I habe to parse this in the Shell-Script?

Would be nice, if anyone could help me here. (If someone saw, that I deleted the Question: sorry, I thought, the ? was the final solution. But it didn work either).

Here is the output of udevadm info --attribute-walk -name /dev/sda1

  looking at device '/devices/platform/fsl-ehci.1/usb1/1-1/1-1:1.0/host2/target2:0:0/2:0:0:0/block/sda/sda1':
    KERNEL=="sda1"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{partition}=="1"
    ATTR{start}=="63"
    ATTR{size}=="1526112"
    ATTR{alignment_offset}=="0"
    ATTR{discard_alignment}=="4294935040"
    ATTR{stat}=="       0        0        0        0        0        0        0        0        0        0        0"
    ATTR{inflight}=="       0        0"

  looking at parent device '/devices/platform/fsl-ehci.1/usb1/1-1/1-1:1.0/host2/target2:0:0/2:0:0:0/block/sda':
    KERNELS=="sda"
    SUBSYSTEMS=="block"
    DRIVERS==""
    ATTRS{range}=="16"
    ATTRS{ext_range}=="256"
    ATTRS{removable}=="1"
    ATTRS{ro}=="0"
    ATTRS{size}=="15656960"
    ATTRS{alignment_offset}=="0"
    ATTRS{discard_alignment}=="0"
    ATTRS{capability}=="51"
    ATTRS{stat}=="       1        0        8        4        0        0        0        0        0        4        4"
    ATTRS{inflight}=="       0        0"
Rustam
  • 1,875
  • 2
  • 16
  • 33
nico
  • 1,039
  • 4
  • 13
  • 27

2 Answers2

0

How about just having the script exit when it's called with /dev/sd??* ?

Christoffer Hammarström
  • 27,242
  • 4
  • 49
  • 58
0
SUBSYSTEM=="block", ACTION=="add", KERNELS=="sd*[!0-9]", RUN+="/script param1 %k"

sd* will match any characters, but [!0-9] will exclude the partition numbers, so you're left with block devices only.

At least on a CentOS 6 systems there are a lot of rules in /lib/udev/rules.d. The rule file 60-persistent-storage.rules defines rules like the one above.

ahochin
  • 21
  • 4