0
votes

I'm trying to run an shell script, if a special usb device is connected to my raspberry pi. I have tried to follow following description:

http://ubuntuforums.org/archive/index.php/t-502864.html

I created a file named 85-my_rule.rules with the content: ACTION=="add",SUBSYSTEM=="usb_device",SYSFS{idVendor}=="ffff",SYSFS{idProduct}=="1000",RUN+="/usr/bin/usbdevinserted"

My script usbdevinserted has the following content: echo "Dies ist ein Text" >>/tmp/text

If I execute this script on the shell, the text file named text ist created with the content "Dies ist ein Text", so the script works fine. But it seems not to be executed, if I connect an usb device to the rasppi. So I think, the error is in my rule, but I cannot found it. Can anyone help me please?

Greetings, Andreas

2

2 Answers

0
votes

Are the vendor and product ID correct?

ffff and 1000 looks weird but it may be possible (e.g some eval board).

Usually, "dmesg" prints out VID/PID (plug/unplug a couple of times, "dmesg", check the last lines)

Also, double-check whether it's a hex-decimal conversion problem (try decimal 65535 and 4096)

0
votes

i found the solution. I had to change my rule to the following rule:

ACTION=="add",SUBSYSTEM=="block",KERNEL=="sd*[!0-9]|sr*",RUN+="/usr/bin/usbdevinserted"

and my script is now:

#!/bin/bash
echo "Dies ist ein Text" >>/tmp/text

but I do not know why I had to insert the first line in my script. Can anybody explain this line please?

Greetings, Andreas