Ubuntu: Need a udev rule to create a symbolic link to a usb memory stick when it is plugged in



Question:

My usb drive has id 580000911. It gets mounted as /media/ubuntu/580000911. I would like a udev rule to create a symbolic link to it like this /media/ubuntu/USBDRIVE. I created this udev rule file:

ACTION=="add", ENV{ID_BUS}=="usb", ENV{ID_FS_LABEL}=="58??????", \  RUN+="rm /media/ubuntu/USBDRIVE", \  RUN+="ln -s /media/ubuntu/$env{ID_FS_LABEL} /media/ubuntu/USBDRIVE"  ACTION=="remove", ENV{ID_BUS}=="usb", ENV{ID_FS_LABEL}=="58??????", \  RUN+="rm /media/ubuntu/USBDRIVE"  

It does not work. I don't know if I am on the right track or not. Any suggestions?


Solution:1

This works:

ACTION=="add", ENV{ID_BUS}=="usb", ENV{ID_FS_LABEL}=="58??????", RUN+="/bin/rm /media/ubuntu/USB", RUN+="/bin/ln -s /media/ubuntu/$env{ID_FS_LABEL} /media/ubuntu/USB"  ACTION=="remove", ENV{ID_BUS}=="usb", ENV{ID_FS_LABEL}=="58??????", RUN+="/bin/rm /media/ubuntu/USB"  

Apparently we have to use the complete pathname for any commands we want to run.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »