Simple unix program to automatically copy file from usb to hard disk
Please tell me a simple unix program to automatically copy a file or folder to the hard d开发者_开发知识库isk when the usb disk is inserted into the usb-port
There are simple ways of copying files over from disks, mainly cp
, however there is no way to 'autorun' scripts on a flash drive, unless you use a cron job, or maybe edit some udev rules, however I'm not sure udev can run shell scripts.
If it can, they can only be run from the host filesystem; not the USB disk.
Thanks,
James
You would probably have to write a program that listens for the particular DBUS event, A dirtier way might be to grep dmesg every few seconds for your device, when it finds it use cp or rsync to transfer the files.
Write udev rule. Something like this:
KERNEL=="sd*", SUBSYSTEMS=="scsi", ATTRS{model}=="USB 2.0 Storage Device", RUN+="/somewhere/copy.sh"
You can find more information on udev rules here: http://www.reactivated.net/writing_udev_rules.html#example-usbhdd
Edit: on ubuntu you need to put this rule to /etc/udev/rules.d/80-usbcopy.rules
精彩评论