[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Checking for a mount in a shell script



On May 20, 2025, Lee wrote:
> On Tue, May 20, 2025 at 6:00 AM Jonathan Dowland wrote:
> >
> > On Tue May 20, 2025 at 6:41 AM BST, Kamil Jońca wrote:
> > > why not
> > > if ! mountpoint  /mnt/usb-drive-b ; then ...
> > > ?
> >
> > I'd not heard of either `mountpoint` or `findmnt` before. I see they're
> > both part of util-linux, so I guess as likely as each other to be
> > available (which is one criterion I would use for choosing)
> >
> > The approach I would have used (and it's not infallible) is
> >
> >         test -f /mnt/usb-drive-b/.some-file
> >
> > where '.some-file' exists on the device but not on the empty mount
> > point.
> 
> If we're continuing this thread, why would one want to use
> /mnt/usb-drive-b for mounting a usb drive instead of automatically
> mounting to
> /media/$USER/filesystem-UUID ?

I used /mnt/backup because I only wanted the partition mounted while the
backup was running (it was one of several on that physical drive). The
backup script did the mount/rsync/unmount as part of the execution.
Really, the only point of this was a "well, I can't accidentally delete
it if it's not mounted" train of thought.

Now, the daily driver backs up to an old desktop (that I rarely interact
with "directly"), so I'm less concerned about the chances of accidental
deletion -- even if I do manage to delete the backups entirely, the
originals are still on the PC (and monthly exports out of the house
anyway).

-- 
|_|O|_| 
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860

Attachment: signature.asc
Description: PGP signature


Reply to: