(ubuntu 16.04) .rules file /etc/udev/rules.d/ does not seem to do job

11,698

I think the problem may be that your rule file 10-local.rules is far too early in the execution list. If you rename it 95-local.rules and reload the rules with sudo udevadm control --reload (if necessary on your system), then you may have more success. Note, there is never any output from udev, so an echo in your script needs to be to a file.

The values shown by udevadm info that begin E: are ENV{} properties that may be set by earlier rules, so you should put your rules as late as possible.

Share:
11,698

Related videos on Youtube

Vivek
Author by

Vivek

Updated on September 18, 2022

Comments

  • Vivek
    Vivek over 1 year

    What I plan to achieve:

    I am trying to automatically run a script when a certain SD card is inserted.

    FACTS:

    a. Script I plan to run is in /home/vivek/Desktop/Message.sh and has the following script in it. Its permissions are set as being an executable file:

    #!/bin/sh
    echo "Card is now inserted"
    

    b. Under /etc/udev/rules.d my rules file is called 10-local.rules and has the following rule in it:

    ENV{ID_FS_UUID}=="C097-C12A", ACTION == "add", RUN+="/bin/sh /home/vivek/Desktop/Message.sh"
    

    c. The ENV{ID_FS_UUID} of my SD card is detected by udevadm is as follows:

    enter image description here

    d. My rules file in /etc/udev/rules.d/ is being processed as found by 'udevadm test' pictured below:

    enter image description here

    ISSUE: When I insert my SD card it mounts fine. But my SCRIPT NEVER GETS EXECUTED! Any help is appreciated.

    Cheers

    • Elder Geek
      Elder Geek over 7 years
    • Vivek
      Vivek over 7 years
      Thanks. I just looked it up. It does not seem to be directly contextual to my issue. In my problem, I seem to be doing all the right things. But, obviously, am missing something. Not able to figure out.
    • Elder Geek
      Elder Geek over 7 years
      It would seem to me that you are attempting to autorun a specific script upon insertion of a specific media mounted by udev. Did I misunderstand your question?
    • Vivek
      Vivek over 7 years
      You are right. I would like to automatically execute a certain script when a certain SD card is inserted.
    • Elder Geek
      Elder Geek over 7 years
      Thats why I believe the link I provided to you is directly applicable to your issue. Did you try the solution there? Did it succeed or fail?
    • Vivek
      Vivek over 7 years
      My script is not on the SD card as is in the example you provide. Instead, my script resides on the machine in a certain folder and must be called by udev processes. So the example you provided does not quite apply, unless I am missing something.
    • Elder Geek
      Elder Geek over 7 years
      I've reviewed your script as posted and see no reason why it can't be placed on the card unless I'm missing something. feasible as the images are hard to read
    • Vivek
      Vivek over 7 years
      Well I can place it on the card for this particular card. But what i intend to do is run different scripts for different devices that are connected to this computer. EG: A USB Stick, A Camera, a Hard Drive, A printer or many other such things. So placing a script on the card may not be very useful to me, unfortunately. Thanks for thinking of a solution, but, that may not be the one I am looking for.
    • Elder Geek
      Elder Geek over 7 years
      If I'm understanding your intent, you might wish to consider that the Device IDs are specific to that device and will not be the same from one device to another even if they share a type. Related: superuser.com/questions/521402/…
    • Vivek
      Vivek over 7 years
      Yes. I plan to use a combination of the KERNEL, SUBSYSTEMS, UUID etc... so I can uniquely identify what has been connected and accordingly execute an external script
    • Mark Plotnick
      Mark Plotnick over 7 years
      If you change echo "Card is now inserted" to echo "Card is now inserted" > /tmp/foo, does that file get created?
    • Elder Geek
      Elder Geek over 7 years
      In that case you might wish to read the Related link I left you most carefully.
  • Vivek
    Vivek over 7 years
    Thanks @meuh. That made sense at first. But then remember that 10-local.rules is the only file in /etc/udev/rules.d/ so it may not matter what I rename it to be. However, I am going to try to rename it to something like a 99zzz.rules an dplace it in /lib/udev/rules.d/ in the odd event that ENV{} is being worked upon there and will come back with finding.
  • Vivek
    Vivek over 7 years
    It worked when I put my new file in /lib/udev/rules.d as the file that is executed last in sequence! Thanks @meuh for the idea.
  • meuh
    meuh over 7 years
    The files in /etc/udev/rules.d/ and /usr/lib/udev/rules.d/ are merged by order of filename, so normally local changes are made in /etc/udev/rules.d/.
  • Vivek
    Vivek over 7 years
    I am trying to detect USB insert regardless of the device it is. Eg: A phone, a battery pack, a biometric system etc.. which may or may not be recognized by Linux (no drivers or nothing to "Drive/run") Linux will, detect the USB insert, and then proceed to register and act on Recognized devices. For instance it will list USB device details in /dev/bus/usb/ etc... I would like to trap/process everything that is inserted into USB. This means, no dependence on stuff like udevadm. Also means I will need to trap the insert event early on the curve. How do I do this?
  • Vivek
    Vivek over 7 years
    The one above is a new question, which I was wondering if I could get some on :) Pardon the super terse language, had a character count limitation. lol!
  • meuh
    meuh over 7 years
    You should probably post a new question with more details on what you actually want to achieve, e.g. you want Linux to ignore all usb devices except your sd card.