This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

udev rules for USB memory stick



 

Hi,

I am using dvsdk4.0 for DM365 processor. I am trying to set a rule within udev that will launch a shell script when a USB memory stick is connected.

With root privilege, I have placed in /etc/udev/rules.d/ folder the rule script with a name: 99-usbdetect.rules.

99-usbdetect.rules file is as follows;

ACTION=="add", KERNEL=="sda", RUN+="/usr/share/myscript.sh"

myscript.sh file is as follows:

#!/bin/sh

echo "hello"

the rule does not seem to be executed and the shell script.

Is there anyone who can tell what's wrong with what is being done.

Thank you

KB

 

  • KB,

      Output may not get displayed on the terminal.

    Form the udev manual,

    udev does not run these programs on any active terminal, and it does not execute them under the context of a shell. Be sure to ensure your program is marked executable, if it is a shell script ensure it starts with an appropriate shebang (e.g. #!/bin/sh), and do not expect any standard output to appear on your terminal

    Can you try redirecting the output to the file?  

       echo "hello" > file

     

     

    Regards,

    N.Sugumar

  • N.Sugumar,

    thx for your reply.

    I did redirect the output of the script to a file. But the file is not created. So that tells me that the 99-usbdetect.rules is not launched.

    I just found out the problem and now it is working.

    The script permission was set as 544. I changed script permission to 755 with chmod command such that when Linux boot, the execution permission is enabled for root.

    Thx

    KB