2

I'm quite desperate after several tryouts of making a quite simple backup program. After 6 hours of following and trying all posts on that topic, I don't know any solution. I just want a java script to start as soon as I plug in a USB drive.

sudoedit /etc/udev/rules.d/90-local.rules

In my local rules I basically, just want to run my SUPERJAVA shell I tried already all kind of ATTRS / ATTR combinations. My last state is:

BUS=="usb", KERNEL=="sd*", ATTRS{serial}=="4C530009320619116345", ACTION=="add", SYMLINK+="kram", RUN+="/home/d/Desktop/DirSyncPro-1.51-Linux/SUPERJAVA.sh"

The shell, just starts a simple Sync program, but works in itself if I start it regularly in the terminal.

#!/bin/bash     java -jar dirsyncpro.jar

However, in the log file, it doesn't make any effort to run the program, if I plug in the USB.

tail -f /var/log/syslog 

Just to get back the steps: 1. lsusb, which gives me: entBus 002 Device 012: ID 0781:5572 SanDisk Corp. 2. udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/002/012), which gives me: looking at device '/devices/pci0000:00/0000:00:1d.7/usb2/2-2': KERNEL=="2-2" SUBSYSTEM=="usb" ...ATTR{idVendor}=="0781" ...ATTR{serial}=="4C530009320619116345" ...ATTR{idProduct}=="5572" ...ATTR{product}=="Cruzer Switch" ...ATTRS{idVendor}=="1d6b" ...ATTRS{idProduct}=="0002" ...ATTRS{product}=="EHCI Host Controller" ...

Does anyone has another idea what I could try? Is udev not compatible anymore with Ubuntu 14.04?

4
  • udev rules are perfectly compatible with 14.04. What you are trying to achieve is fairly standard. Where does your usb volume mount (with cat /etc/mtab and more /proc/mounts) ? In what way is your usb medium involved in your backup process ? I.e. where does it come in when you run /home/d/Desktop/DirSyncPro-1.51-Linux/SUPERJAVA.sh ? Please edit your question so we can help. Please respond with @Cbhihe.
    – Cbhihe
    Oct 24, 2015 at 12:59
  • @Cbhihe thanks a lot for your answer. Basically as soon as I mount the usb, SUPERJAVA.sh should just start the program dirsyncpro.jar DirSyncPro handles the backup process. As it could have been any other program... But this doesn't happen. What do you mean by "Where does your usb volume mount?" Oct 25, 2015 at 15:04
  • What I mean by "Where does your usb volume mount?" is: can you show us yr mount point with cat /etc/mtab; more /proc/mounts ?
    – Cbhihe
    Oct 25, 2015 at 19:43
  • @Cbhihe Ok thanks. I guess this must be the information for the usb: /dev/sdb1 /media/d/B8A3-F495 vfat rw,nosuid,nodev,relatime,uid=1000,gid=1000,fma sk=0022,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf 8,flush,errors=remount-ro 0 0 Oct 27, 2015 at 12:38

2 Answers 2

0

Your udev rule does not fire.

Replace:

  • BUS=="usb" with SUBSYSTEM=="usb".
  • KERNEL=="sd*" with KERNEL=="2-2".

Triple check:

  • your serial number ATTRS{serial}=="4C530009320619116345".
  • the path to your script.

Suppress (momentarily) SYMLINK+="kram". You can add it back later when you are satisfied that yr rule works.

Your new udev rule should be:

SUBSYSTEM=="usb", KERNEL=="2-2", ATTRS{serial}=="4C530009320619116345", ACTION=="add", RUN+="/home/d/Desktop/DirSyncPro-1.51-Linux/SUPERJAVA.sh"

If this works, try it without the udev tag KERNEL=="2-2" as it may be superfluous, especially if you successfully idetify yr event device with its serial number.

4
  • Thanks for the answer, but still nothing happens if I plug-in the usb. Oct 28, 2015 at 14:59
  • @fahrradlaus: Well sorry, but that udev rule should work. Try replacing your script call with : RUN+="/bin/echo hello > /home/d/Desktop/foobar.txt". If that works, it means my answer is good and your script bad. It it does not work then, sorry .... o_0 ... but I am stumped. Let us know anyway.
    – Cbhihe
    Oct 28, 2015 at 16:46
  • @fahrradlaus: BTW....... I never mentionned that, but I assumed that after each modification of your udev rule, you did (in terminal): sudo service udev restart. Did you do it before ?
    – Cbhihe
    Oct 28, 2015 at 16:48
  • I'm sorry I got totally stuck with this. Also your script doesn't work. No idea what goes wrong there. I even tried to save two rules one calling the USB key, the other the device. 10-local.rules: SUBSYSTEM=="usb", ATTR{serial}=="4C530009320619116345", ACTION=="add", RUN+="/bin/echo hello > /home/d/Desktop/foobar.txt" the other 90-local.rules: SUBSYSTEMS=="usb", KERNELS=="usb2", ATTRS{serial}=="0000:00:1d.7", ACTION=="add", RUN+="/bin/echo hello > /home/d/Desktop/foobar.txt" Oct 29, 2015 at 17:46
0

udev is not for long processes, check man udev. look for udev binding or just shell, watch for udev event. Do sync at user level.

udevadm monitor -u may help, python have pyudev, ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .