0

I'm trying to use udev for some basic actions, in this case the idea is to launch a simple script. The problem is that when I use this rule:

ACTION=="remove", ENV{ID_FS_LABEL}=="NAMEHERE", KERNEL=="sd[a-z][0-9]", RUN+="/home/foobar/Scrapyard/the_script.sh"

It runs perfect, but if I use this one:

ACTION=="add", ENV{ID_FS_LABEL}=="NAMEHERE", KERNEL=="sd[a-z][0-9]", RUN+="/home/foobar/Scrapyard/the_script.sh"

No action is done! I'm trying to trigger an action when an usb with a label "NAMEHERE" is connected, NOT disconnected.

  • Quick shot: It may not have the ID_FS_LABEL at the point where you are calling the rule, because it will need to run some other rule (calling blkid or whatever, can't remember) to determine the label in the first place. – dirkt Sep 13 '18 at 12:24
  • First at all, thanks for your time dirkt... blkid os similar before using this rule maybe? – Brokes Sep 13 '18 at 12:26
1

Now, with some extra research, the problem fixed or at least I think so:

# If not an usb... End the execution
KERNEL!="sd[a-z][0-9]", GOTO="media_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"  
ACTION=="add", ENV{ID_FS_LABEL}=="PERAMA",  RUN+="/home/gizquierdo/Scrapyard/elScriptejo.sh"
LABEL="media_mount_end"
  • 1
    I guess a cleaner solution would be to let the other rule which does blkid anyway run first, or it'll get run twice... but that means you'll need to find out which rule this is. But if you don't mind the extra overhead, do whatever works for you. – dirkt Sep 13 '18 at 13:28

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.