linux - Copy files to my usb ONLY in shell script -
i need write sh script copy files hard drive connected usb. connected usb same 1 , want make sure these non computer savvy people don't copy usb. script needs copied multiple linux computers can have different number of partitions or numer of usbs connected. data protection not important.
my first thought: copy files "my usb flash drives name". way if usb name gets connected, data not copied it.
how ?
first, plug usb in , @ dmesg:
$ dmesg
and see like:
[98937.147950] sd 15:0:0:0: [sdb] attached scsi removable disk
then go /dev , gather uuid of pendrive:
$ ls /dev/disk/by-uuid/ -l
...
98a9-d422 -> ../../sdb1
now can make script this:
#!/bin/bash mkdir /mnt/my_pendrive mount /dev/disk/by-uuid/98a9-d422 /mnt/my_pendrive
...
and work in every computer, uuid same anywhere plug pendrive in
whenever want check whether precisely pendrive has been connected, check /dev/disk/by-uuid/ directory see if 98a9-d422 exists.
Comments
Post a Comment