4

I've written 2 rules in udev for usb add and removed in 2 files.

SUBSYSTEM=="usb", ACTION=="add", RUN+="/u/usb_added %b"
SUBSYSTEM=="usb", ACTION=="remove", RUN+="/u/usb_remove %b"

I have created two different scripts for these rules that take appropriate action (doing same thing).

I want to combine these rules (and then action script) by passing values (add, remove) and then check in new script by if condition. and then take proper action.

so my question is how i can pass parameters in RUN+= "/u/usb_status ??"

how i will get these parameters in new script and then use in if condition.

thanks in advance.

user115079
  • 711
  • 1
  • 11
  • 23

2 Answers2

2

As far as i know, you can do like this:

SUBSYSTEM=="usb", RUN+="scripts %b"

And then in scripts use this:

if [ $ACTION == "add" ];then
  .....
elif [ $ACTION == "remove" ]lthen
  .....

But this seems limit by the version of udev... I don't know ,try it.

Charles Menguy
  • 40,830
  • 17
  • 95
  • 117
Rainlight
  • 81
  • 1
  • 6
2

I solved it by just writing word after executing script.

for example:

SUBSYSTEM=="usb", ACTION=="add", RUN+="/u/usb_added Parameter %b"

So I just used it as:

SUBSYSTEM=="usb", ACTION=="add", RUN+="/u/usb_added ADDED %b"

and in executing script ( in this case usb_added) i got it as follow:

CHECK=$@

Now value of this CHECK is "ADDED" that was actually passed from Udev rule.

user115079
  • 711
  • 1
  • 11
  • 23