How can I determine the address of a pen drive in Linux?
My task is to create a file on my pen drive dynamically - as soon as I insert the pen drive, the file should be created.
How can I determine the address of a pen drive in Linux?
My task is to create a file on my pen drive dynamically - as soon as I insert the pen drive, the file should be created.
I would recommend using udev.
Edit: Here's a similar question which was posted in 2007. http://www.linuxquestions.org/questions/linux-software-2/how-to-detect-programatically-if-a-usb-device-is-is-plugged-in-plugged-out-524568/
In Ubuntu at least (meaning that the drive automounts), a drive's files can be found under /media/<drivelabel>. The drive label is either something random if you didn't set one or what you set it to.
+1 for the UDEV Create an UDEV rule that runs a script, whenever a device with a specific UUID is inserted.
To determine the mountpoint of a device with e.g. uuid of "95738a33-589f-498d-8595-a81207f45dde", you can use the following ugly-but-working one-liner:
grep $(ls -lah /dev/disk/by-uuid/95738a33-589f-498d-8595-a81207f45dde | grep -o "sd[a-z]*[0-9]*") /etc/mtab | awk '{print $2}'