Udev rules failing to pass parameters

3

Linux newbie on Gentoo here. I am trying to write a udev rule that would run a Python script and pass some information whenever a usb device (specifically a usb modem) is inserted. I have:

SUBSYSTEM == "usb", ACTION == "add", $ATTRS{vendor} = "?*", RUN += "/home/.../notify.py %k '$attr{vendor}'"

as a starting point.

Right now, notify.py is an executable trying to help me debug and looks like:

#!/usr/bin/python
import sys
log = open("log.txt", 'a')
for a in sys.argv:
    log.write(a + "\n")
fi.close()

I cannot figure out how to get "$attr{vendor}" to pass; right now, only %k (the kernel of the device) is passed and printed, along with any other string arguments I feel like adding. I've been all over the internet, I've tried "$attr{vendor}" (outputs nothing), "$attrs{vendor}" (outputs "s{vendor}"), and "%s{vendor}"(outputs nothing). I've tried changing the priority of this rule, in case variables weren't being defined yet or something. I've looked at other rules files, and none of them do quite what I'm doing, but they do manage to use "$attr{[something]}".

Still confusing is, if I write something like

GOTO+="$attr{vendor}"

vi highlights it as a string, but

RUN+="$attr{vendor}"

and vi highlights everything differently. I feel like the bug has something to do with the way RUN works, or with my improper usage of "$attr", but I'm totally lost.

These posts seem to do something similar to what I am trying to do. I'd appreciate any help or input on this problem.

Ivoirians

Posted 2012-07-20T18:33:51.770

Reputation: 151

Answers

2

In case it helps someone one day, I found two steps that helped me solve the problem.

The first was to ensure that the rule had selected a parent device to pull attribute information from, so I added a

ATTRS{bDeviceClass} == "02"

to have the rule link to the desired network device.

The second step, which might have been unnecessary after the first step, was to set an environment variable and call it as such:

ENV{var} = ATTRS{bDeviceClass}, RUN+="/home/.../notify.py '$env{var}'"

This successfully passed the variable. In the end, it seemed like $attr and %s still did not work. I'd been stuck on this so long I lack the motivation right now to play around with things.

Ivoirians

Posted 2012-07-20T18:33:51.770

Reputation: 151