Reputation: 11
I'm looking for a way to copy a file to usb drive then inserted, automaticaly. I need to:
I need to do this with linux bash. I already searched for some useful commands as udev, mount, udevinfo but really don't know how to used them (combine them) to get what I need.
Any suggestions?
Upvotes: 0
Views: 3780
Reputation: 1
I kind of got it, it is functional, but the only things I have not fixed is:
the good thing is that you don't need to copy any file onto the usb, just plug in and the file will be copied onto it automatically. Hope this helps someone else, or can be improved. (sorry the explanation below is in spanish...)
KERNEL=="sdb2", RUN+="/home/adario/paraCopiar/autocopiar"
Lo que hace es que cuando se inserta la memoria usb ejecuta el script de la ubicacion (el código 81 es importante, ya que dependiendo de lo que pongamos se ejecuta antes o despues de las demas reglas, o no se ejecuta. El resto del nombre puede ser lo que querramos).
sudo mount /dev/sdb2 /mnt/acopiar -t vfat -o umask=000 cp -v /home/adario/paraCopiar/loqueQuieroCopiar.zip /mnt/acopiar
Lo que hace es asignar otro punto de montaje al usb que ya se ha montado, èsto para que sepamos el nombre de la ubicación.
nombreUsuario ALL=(ALL) NOPASSWD: ALL
Upvotes: 0
Reputation: 20229
I have not written any udev rules myself, but the answer from "etola" in this Ubuntu forum thread describes exactly your use case (execute a script when a device shows up). However it's IMHO sensitive to each device that you plug in, so you may need more than one entry.
There's also a manual about writing udev rules.
Upvotes: 1