Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/.../ %k '$attr{vendor}'"

as a starting point.

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

import sys
log = open("log.txt", 'a')
for a in sys.argv:
    log.write(a + "\n")

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


vi highlights it as a string, but


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.

share|improve this question

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/.../ '$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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .