2

As probably thousands of us I wanted to have special script running when "this one" usb stick is inserted. But also I want to have something running when it's removed - this is pain in the ass. I did read about issues with correct matching removal here: https://www.linuxquestions.org/questions/linux-desktop-74/udev-not-doing-remove-rules-841733/

So. My rules are:

ACTION=="add", SUBSYSTEMS=="scsi", ATTRS{model}=="USB2FlashStorage", ATTRS{vendor}=="Ut165   ", ENV{UDISKS_IGNORE}="1", ENV{PX2_KEY}="1", SYMLINK+="key%n", OWNER="root", RUN+="/root/bin/key.sh add"
ACTION=="remove", SUBSYSTEM=="bsg", ENV{PX2_KEY}=="1", RUN+="/root/bin/key.sh del"

Add one works perfectly but remove doesn't at all. I tried to use with and w/o SUBSYSTEM (usb, block, scsi), with or without correct ENV{ID_MODEL}, ID_VENDOR, ID_SERIAL, ID_F..._POOP and nothing. On the current stage you can see that I'm creating own symlink (key%n) and tried use that as well with

KERNEL=="key*"

no luck! You probably noticed also I'm setting my own variable (PX2_KEY) and trying to match by this and... no luck as well... What am I doing wrong... Maybe I'm missing something on rules order but did try making my rule file 10-local as well as 99-local - didn't work. Add works, remove not. bsg is set because this is the first subsystem where I see udev shows existence of PX2_KEY in

udevadm monitor --udev --environment

when remove is done. Thought maybe I need to catch first occurence. But tried different too.

1

It works.

I'm not too smart. The issue was that in the script I wanted to run, I run zenity with --display=:0 as root trying to write message for different user.

Script ended before any "logging" part...

| improve this answer | |
  • 1
    No, you are smart for figuring it out. Well done! – George Udosen Mar 14 '17 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.