I have a USB device (Pen drive) that collects a lot of data a fills up its storage regularly. The goal is to write a script that:
- accesses USB device
- mounts it as a storage device
- downloads data from the device
- safely unmounts the device for removal (upon completion of the download)
I found this question.
I have done all things from this but my udev rules are not reflected.
The shell script which I have set in .rules
file is not running on USB mount. My rules file is /etc/udev/rules.d/99-mydevice.rules
:
KERNEL=="sd*",SUBSYSTEM=="usb",ATTR{idVendor}="1d6b",ATTR{idProduct}="0002",ATTR{serial}="3f980000.usb",RUN+="/home/pi/newfile.sh"
and my USB system path is /sys/bus/usb/devices/usb1
Am I missing something?
2 Answers 2
Udev statements containing a single =
are assignments, not comparisons. For example ATTR{idVendor}="1d6b"
tries to assign a newly plugged USB device a particular Vendor ID, and failing since Vendor IDs are read only. You want to use ==
in comparisons.
-
I tried this too but its not working. My script is as follows: #!/bin/bash cp /media/pi/dev_name/test.txt /home/pi/newfile.txt echo File transfer > log.txt Once USB inserted cant get any logs in log.txt. Plz help on this.Prajakta– Prajakta2017年04月03日 05:29:21 +00:00Commented Apr 3, 2017 at 5:29
I tried this and it works for me:
cat /etc/udev/rules.d/11-media-by-label-with-pmount.rules
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end" ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"
PROGRAM=="/sbin/blkid -o value -s LABEL %N", ENV{dir_name}="%c"
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c" ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"
ACTION=="add", ENV{dir_name}!="", RUN+="/bin/su JrtFlash-c '/usr/bin/pmount %N %E{dir_name}'", RUN+="/home/pi/my-script.sh" ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/su JrtFlash-c '/usr/bin/pumount /media/%E{dir_name}'" LABEL="media_by_label_auto_mount_end"
and tested using command: