I am working on a bash script that is designed to tell whether or not a given drive is attached to the system, and if it is, to copy some data (backups that need to be taken off-site) to that drive.
What I’d like to do is identify the drive/partition by UUID, so that I can have a script that frequently scans for the presence of that drive, and when it’s plugged in, copies data to it (via rsync, so I don’t particularly care if that part runs more than once, because the later runs are I/O-cheap). I want this to be as simple as possible so that I can hand the drive in question to a non-technical person and say “plug it in here, then unplug it later and take it with you.”
I can’t seem to find any options in mount that quite do this, and grepping through /etc/fstab doesn’t tell me whether a drive is actually mounted or not.
How can I tell, given a UUID, whether or not a drive with that UUID is mounted and what its mount point is?
/dev/disk/by-uuid/ is a symlink farm for attached volumes. It won’t tell you if the volume is mounted or not but will tell you if it’s plugged in – so might address your particular use case anyway.
Does that help?