3

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

  • have you seen this: askubuntu.com/questions/642511/… – Elder Geek Oct 7 '16 at 21:18
  • 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. – Vivek Oct 7 '16 at 21:21
  • 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? – Elder Geek Oct 7 '16 at 21:23
  • You are right. I would like to automatically execute a certain script when a certain SD card is inserted. – Vivek Oct 7 '16 at 21:30
  • 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? – Elder Geek Oct 7 '16 at 21:32
1

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.

  • 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 Oct 8 '16 at 19:09
  • 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. – Vivek Oct 8 '16 at 19:20
  • 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/. – meuh Oct 8 '16 at 19:41
  • 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 Oct 9 '16 at 2:53
  • 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! – Vivek Oct 9 '16 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.