0
votes

So I want to make a udev rule which does, when I connect my usb key to my computer the rule mounts my usb key, takes a file from my computer, copies it to my usb key and then unmounts my usb. So I did my udev rule like that:

ACTION=="add" SUBSYSTEM=="BLOCK", ENV{ID_VENDOR_ID}=="0718", ENV{ID_MODEL_ID}=="0618", ENV{ID_SERIAL_SHORT}=="CB00524932077759", RUN+="/bin/mount /dev/sda1 /media/usb"
ACTION=="add" SUBSYSTEM=="BLOCK", ENV{ID_VENDOR_ID}=="0718", ENV{ID_MODEL_ID}=="0618", ENV{ID_SERIAL_SHORT}=="CB00524932077759", RUN+="/bin/ScriptCopy"

And I wrote a script, in /bin, called ScriptCopy:

#!/bin/sh

cp /root/average.db /media/usb/database/average.db

ldconfig

echo "Done!"
exit 0

So the first part of my udev rule works, it mounts the usb key, but then my script does not work, I do not really understand why. Can someone explain it to me? Thx

edit 1: when I am running my script in the terminal, doing

./ScriptCopy

it works! so I must have a problem in my udev rule.

edit 2: I found out something really strange (at least, that I don't understand at all), my rule works if I am plugging my USB key while I am on the GUI (XFCE) on my banana pi. But I am working with ssh, so normaly I don't open the GUI. I want to do is, to run some commands with the ssh, trigger my python script and then I take the data with my usb key once every two days. But when I plug my usb while banana pi is not on the GUI (while I triggered my script from another computer using ssh), it does not transfert the data to my usb key. I don't know if it was understandable.

Edit 3: Ok I had an error of path in my UDEV rule because on ssh, I was not in the same user. I am closing the topic.

1
Why do you end your script with a done statement? To the best of my knowledge this defines the end of a loop, which you don't have. Exit the script using exit 0. The 0 defines a successful execution. Although this will probably not solve your issue.ShellFish
Yes you right! My bad, but yes it does not solve my problem neither.Max Taylor
no error messages? Also, can you use #!/bin/bash at top instead? To see debug mode, use set -vx before your cp command. AND have you created your database/ dir on your USB? Finally, if you created script anywhere near MS Windows, do dos2unix ScriptCopy. Good luck.shellter
I forgot to say it, but I am working on bananian (debian for banana pi). And yes I have this directory on my USB. Thank you for your answers!Max Taylor

1 Answers

0
votes

I found that I had an error of path in my script/udev rule.