rego21
Posts: 26
Joined: Fri Feb 16, 2018 4:09 pm

UDEV on the last Raspbian

Fri Feb 16, 2018 4:16 pm

Hello all,

Im trying to make an udev rule able to detect whenever a usb device is connected and then run a script. However it doesn´t work at all, here is the udeve rule:

Code: Select all

ACTION=="add", RUN="/home/pi/device.sh
And the script:

Code: Select all

#!/bin/bash     date >> log.log
Thank you all!

User avatar
topguy
Posts: 5627
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: UDEV on the last Raspbian

Fri Feb 16, 2018 5:31 pm

- I think you need to add something to your rule that matches this USB device.

Example: SUBSYSTEMS=="usb",DRIVERS=="qcserial"
This matches modem which uses the Qualcom driver.

or: ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001"
This matches only USB devices with these two attribute values. These two you can see with "lsusb" .

Also:
- The script can not run for a long time. It will be killed by systemd.
- It can not spawn off a separate script in the background either, that too will be killed by systemd.

You script looks OK, but you are missing a " in your rule, but I'm guessing that might be a cut&paste error.

rego21
Posts: 26
Joined: Fri Feb 16, 2018 4:09 pm

Re: UDEV on the last Raspbian

Fri Feb 16, 2018 5:48 pm

@topguy but i cant make a generic udev rule? I´m new with this, can you guide me please?

User avatar
topguy
Posts: 5627
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: UDEV on the last Raspbian

Fri Feb 16, 2018 6:25 pm

Never tried to make generic rules with udev, my goal has always been to match a specific device and give it a good name or something.
I'm not sure what happens when multiple rules matches for example.

Maybe this could work ??

Code: Select all

SUBSYSTEMS=="usb",  RUN+="/home/pi/device.sh"

rego21
Posts: 26
Joined: Fri Feb 16, 2018 4:09 pm

Re: UDEV on the last Raspbian

Sat Feb 17, 2018 9:13 am

Ok gonna give it a try @topguy!

rego21
Posts: 26
Joined: Fri Feb 16, 2018 4:09 pm

Re: UDEV on the last Raspbian

Sat Feb 17, 2018 11:11 am

Somehow my first rule worked, but dont know how, because i try to plug in and out my usb keyboard and nothing works... I also tried your rule, but no success @topguy...

rego21
Posts: 26
Joined: Fri Feb 16, 2018 4:09 pm

Re: UDEV on the last Raspbian

Sat Feb 17, 2018 11:50 am

Ok very strange, my rule is working now but i dont know why ahah Thanks for your help @topguy!

Return to “General discussion”