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.