Need help running a script with udev when a usb device is plugged in
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2019
    Location
    canada
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help running a script with udev when a usb device is plugged in

    Hi everybody,

    At work, we have a computer with fedora and we use a Wacom tablet. For some reason, everyone using it is left-handed, so we run a script everytime the user login that flips the tablet 180 so we won't press the buttons with our left hand while using it. The thing is that we also use our whole setup with a Windows computer and for that, I made a usb switcher for the wacom to switch between linux and windows.

    Everytime the tablet gets reconnected to fedora, we have to run that script again because it switches back to right handed. So if we switch between computers without logging out everytime, we have to open the script with a terminal (using the tablet upside down) to get it right.

    So I decided to use uDev to run that script everytime the Wacom gets connected, but for some reason, it doesn't work. I'm not a big user of udev nor linux, so if anyone of you can help, it would be really appreciated.

    Here's what I did:

    1 - I created the rule file and added the rule in it (note that the ids are not the ones I used, I'm not at work so I do not have the good ones):
    /etc/udev/rules.d/85-wacom.rules

    Code:
    ACTION=="add", SUBSYSTEM=="usb_device", ATTR{idVendor}=="040a", ATTR{idProduct}=="0576", RUN+="/usr/local/wacom.sh"
    2- I created my sh file:
    /usr/local/wacom.sh

    Code:
    #!/bin/bash
    "Code that rotates the tablet"
    exit
    I made my sh file executable by using "chmod +x file.sh".

    The script is working perfectly fine if I run it using terminal, but nothing will happen if I plug in the Wacom tablet.

    Can anyone help me? Thanks a lot!

  2. #2
    Join Date
    Feb 2019
    Location
    Alberta
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help running a script with udev when a usb device is plugged in

    To get info on my USB key which is currently /dev/sdb for a udev rule, I run command: udevadm info --name=/dev/sdb --attribute-walk
    The first section of the output is as such:
    looking at device '/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1/1-1:1.0/host3/target3:0:0/3:0:0:0/block/sdb':
    KERNEL=="sdb"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{range}=="16"
    ATTR{events}=="media_change"
    ATTR{ext_range}=="256"
    ATTR{hidden}=="0"
    ATTR{inflight}==" 0 0"
    ATTR{events_async}==""
    ATTR{removable}=="1"
    ATTR{discard_alignment}=="0"
    ATTR{ro}=="0"
    ATTR{stat}==" 91 0 4285 531 0 0 0 0 0 100 477 0 0 0 0"
    ATTR{alignment_offset}=="0"
    ATTR{events_poll_msecs}=="-1"
    ATTR{capability}=="51"
    ATTR{size}=="2001888"
    The information in the quote above is in reference to "sdb", highlighted in blue, it is the block device. Every other item before it are devices between it and the CPU. You'll notice how the words: KERNEL, SUBSYSTEM, DRIVER, ATTR, are not pluralized (no "S"), every parent device for sdb, those words will end with an "S".
    Below is the ID information for my key from the section highlighted in red above:
    looking at parent device '/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPower}=="200mA"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0010"
    ATTRS{tx_lanes}=="1"
    ATTRS{version}==" 2.00"
    ATTRS{ltm_capable}=="no"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{idVendor}=="0781"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{urbnum}=="484"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{serial}=="20051535611e0191b529"
    ATTRS{bmAttributes}=="80"
    ATTRS{rx_lanes}=="1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{product}=="Cruzer Mini"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{busnum}=="1"
    ATTRS{quirks}=="0x0"
    ATTRS{idProduct}=="5150"
    ATTRS{removable}=="unknown"
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="1"
    ATTRS{manufacturer}=="SanDisk Corporation"
    ATTRS{maxchild}=="0"
    ATTRS{authorized}=="1"
    ATTRS{bDeviceClass}=="00"
    ATTRS{configuration}==""
    Using your rule with my key, this is how the rule should look:
    ACTION=="add", SUBSYSTEM=="block", ATTRS{idVendor}=="0781", ATTRS{idProduct}=="5150", RUN+="/bin/bash /usr/local/wacom.sh"
    You may or may not need the "/bin/bash", some examples say it is required to tell udev which shell to use to execute the command. I would do this:
    ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0781", ATTRS{idProduct}=="5150", RUN+="/bin/bash /usr/local/wacom.sh"
    Last edited by BrainBoy; 16th March 2019 at 04:59 AM.

Similar Threads

  1. Replies: 0
    Last Post: 29th June 2016, 04:27 PM
  2. Replies: 3
    Last Post: 25th March 2011, 02:55 PM
  3. SAMSUNG bluetooth device plugged in, then what ?
    By mha in forum Servers & Networking
    Replies: 0
    Last Post: 3rd January 2009, 01:44 PM
  4. Replies: 0
    Last Post: 1st February 2006, 10:29 AM
  5. Hangs on boot with any USB device plugged in
    By The Warlock in forum Using Fedora
    Replies: 5
    Last Post: 27th July 2005, 08:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •