0

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

1

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.

answered Mar 31, 2017 at 7:48
1
  • 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. Commented Apr 3, 2017 at 5:29
0

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:

udevadm test $(udevadm info -q sys-path) 2>&1

answered Apr 4, 2017 at 10:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.