Re: quick scripting 'is /P/Q mounted'
On Tue, Mar 13, 2018 at 03:56:00PM -0400, The Wanderer wrote: > On 2018-03-13 at 15:39, Joe wrote: > > > On Tue, 13 Mar 2018 14:49:56 +0100wrote: > > That test can be spoofed, however, by the creation of a directory with > the same name (and/or other characteristics) under the mount point while > the mount is not active. > Yes, but in most use cases one would not be worried about malicious actions, you are trying to protect against cock-ups. > Even if you don't think anything malicious is ever going to try to spoof > this in whatever case is at hand, can you be sure no script (or, for > that matter, user) will ever attempt to create that directory under the > mistaken impression that the mount is active? > Yeah, that's a fair point though. Mark
Re: quick scripting 'is /P/Q mounted'
On Tue, 13 Mar 2018 15:56:00 -0400 The Wandererwrote: > On 2018-03-13 at 15:39, Joe wrote: > > > On Tue, 13 Mar 2018 14:49:56 +0100 wrote: > > >> On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote: > > >>> Unless I've misunderstood the question, you can tell if > >>> something is mounted at a mount point by checking if anything is > >>> present under the mount point [...] > >> > >> Not if the file system is really empty (and no, lost+found doesn't > >> really count, since not all file systems have that). > > > > But one use-case is unattended synchronisation, possibly over a > > network. If the directory is mounted, but with some kind of problem, > > then a check for mounting could succeed without any data being > > visible to the synchronising application. In the worst case, the > > backup directory might be synchronised to an apparently empty > > one > > > > I prefer to test for the existence of a known lower directory in > > this case, which tests not only for mounting but for a successful > > read. > > That test can be spoofed, however, by the creation of a directory with > the same name (and/or other characteristics) under the mount point > while the mount is not active. > > Even if you don't think anything malicious is ever going to try to > spoof this in whatever case is at hand, can you be sure no script > (or, for that matter, user) will ever attempt to create that > directory under the mistaken impression that the mount is active? > Reasonably, because the only program likely to create it would be the synchroniser itself, which should have been prevented from running because it wasn't there to start with. If it did happen, nothing would be getting wiped, just a spurious copy created on a drive that doesn't contain any system stuff, so I wouldn't worry too much. The wiping of one of the sync targets *might* be catastrophic (and might lead to the other getting wiped on the next sync) and is completely unacceptable. Yes, synchronisers do have some protection against this kind of error, but I like to use belt, braces, and skyhooks when available. Should I worry about your scenario, I could take it further, with utterly improbably-named directories or files containing specific data, but so far I haven't. -- Joe -- Joe
Re: quick scripting 'is /P/Q mounted'
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tue, Mar 13, 2018 at 03:56:00PM -0400, The Wanderer wrote: > On 2018-03-13 at 15:39, Joe wrote: [...] > > I prefer to test for the existence of a known lower directory in > > this case, which tests not only for mounting but for a successful > > read. > > That test can be spoofed, however, by the creation of a directory with > the same name (and/or other characteristics) under the mount point while > the mount is not active. > > Even if you don't think anything malicious is ever going to try to spoof > this in whatever case is at hand, can you be sure no script (or, for > that matter, user) will ever attempt to create that directory under the > mistaken impression that the mount is active? Seconded. That depends on what you want to achieve, but if this is some kind of backup script, if it manages once (by mistake) to sync to the mount point while no mount is active, it'll keep repeating that mistake forever... Cheers - -- tomás -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlqoM9MACgkQBcgs9XrR2kbJfwCdE45msW7x44N4Ma+HQb57oZKO gMAAnivPzGgYCRXAs6xRRBfVzYwfnrYm =pRcJ -END PGP SIGNATURE-
Re: quick scripting 'is /P/Q mounted'
On 2018-03-13 at 15:39, Joe wrote: > On Tue, 13 Mar 2018 14:49:56 +0100wrote: >> On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote: >>> Unless I've misunderstood the question, you can tell if >>> something is mounted at a mount point by checking if anything is >>> present under the mount point [...] >> >> Not if the file system is really empty (and no, lost+found doesn't >> really count, since not all file systems have that). > > But one use-case is unattended synchronisation, possibly over a > network. If the directory is mounted, but with some kind of problem, > then a check for mounting could succeed without any data being > visible to the synchronising application. In the worst case, the > backup directory might be synchronised to an apparently empty > one > > I prefer to test for the existence of a known lower directory in > this case, which tests not only for mounting but for a successful > read. That test can be spoofed, however, by the creation of a directory with the same name (and/or other characteristics) under the mount point while the mount is not active. Even if you don't think anything malicious is ever going to try to spoof this in whatever case is at hand, can you be sure no script (or, for that matter, user) will ever attempt to create that directory under the mistaken impression that the mount is active? -- The Wanderer The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man. -- George Bernard Shaw signature.asc Description: OpenPGP digital signature
Re: quick scripting 'is /P/Q mounted'
On Tue, 13 Mar 2018 14:49:56 +0100wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote: > > > > > Unless I've misunderstood the question, you can tell if something > > is mounted at a mount point by checking if anything is present > > under the mount point [...] > > Not if the file system is really empty (and no, lost+found doesn't > really count, since not all file systems have that). > But one use-case is unattended synchronisation, possibly over a network. If the directory is mounted, but with some kind of problem, then a check for mounting could succeed without any data being visible to the synchronising application. In the worst case, the backup directory might be synchronised to an apparently empty one I prefer to test for the existence of a known lower directory in this case, which tests not only for mounting but for a successful read. -- Joe
Re: quick scripting 'is /P/Q mounted'
On Tue, Mar 13, 2018 at 07:51:32AM -0700, Mike McClain wrote: > Thank you Richard. > I suspect $(grep /south40/docs/ /proc/mounts) would be faster than But that would be wrong, because it would incorrectly return "true" if you have something mounted at /south40/docs/subdir or /media/south40/docs/ (or if there is a device that contains the string "/south40/docs/" somewhere in its name, etc.). Use the mountpoint command instead. This is why it exists. (Use the -q option in a shell script to suppress the human-readable output.)
Re: quick scripting 'is /P/Q mounted'
Thank you Richard. I suspect $(grep /south40/docs/ /proc/mounts) would be faster than $( mount | grep 'south40/docs'). And I'm sure [ -f /south40/docs/.flag ] would be. Much obliged. Mike On Tue, Mar 13, 2018 at 05:37:07PM +1300, Richard Hector wrote: > On 13/03/18 16:40, Mike McClain wrote: > > If my other computer is South40 and I want to mount South40's /docs > > on my /south40/docs/ directory I can do that. As one script calls > > another I want to know if I need to mount South40 without > > $( mount | grep 'south40/docs'). > > You could look at /proc/mounts, but that's similar to the output of mount. > > Or if it's for a specific directory, and you can put something in it, > you can test for the existence of a special file in the directory. > > Something like > > [ -f /south40/docs/.flag ] > > Richard > -- "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." - Albert Einstein
Re: quick scripting 'is /P/Q mounted'
Thank you David. As it happens I have util-linux installed but as with most of Gnu/Linux there are hundreds of programs I've never used and don't know what do. Appreciate the heads-up. Mike On Tue, Mar 13, 2018 at 08:49:58PM +1100, David wrote: > On 13 March 2018 at 14:40, Mike McClainwrote: > > > > If my other computer is South40 and I want to mount South40's /docs > > on my /south40/docs/ directory I can do that. As one script calls > > another I want to know if I need to mount South40 without > > $( mount | grep 'south40/docs'). > > > > Suggestions? > > Installing the package util-linux will provide the mountpoint command > which exits true=0 if its argument is in use as a mountpoint. Example: > > $ if mountpoint / ; then echo "exit status is $?" ; fi > / is a mountpoint > exit status is 0 -- "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." - Albert Einstein
Re: quick scripting 'is /P/Q mounted'
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote: > On Tue, Mar 13, 2018 at 08:49:58PM +1100, David wrote: > > On 13 March 2018 at 14:40, Mike McClainwrote: > > > > > > If my other computer is South40 and I want to mount South40's /docs > > > on my /south40/docs/ directory I can do that. As one script calls > > > another I want to know if I need to mount South40 without > > > $( mount | grep 'south40/docs'). > > > > > > Suggestions? > > > > Installing the package util-linux will provide the mountpoint command > > which exits true=0 if its argument is in use as a mountpoint. Example: > > > > $ if mountpoint / ; then echo "exit status is $?" ; fi > > / is a mountpoint > > exit status is 0 > > > Unless I've misunderstood the question, you can tell if something is > mounted at a mount point by checking if anything is present under the > mount point [...] Not if the file system is really empty (and no, lost+found doesn't really count, since not all file systems have that). Watch this: tomas@trotzki:~$ dd if=/dev/zero of=fatty bs=1024 count=1024 1024+0 records in 1024+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00582808 s, 180 MB/s tomas@trotzki:~$ mkfs.vfat fatty bash: mkfs.vfat: command not found tomas@trotzki:~$ /sbin/mkfs.vfat fatty mkfs.fat 4.1 (2017-01-24) tomas@trotzki:~$ sudo mount -ouid=tomas,gid=tomas fatty /mnt [sudo] password for tomas: tomas@trotzki:~$ ls -al /mnt total 20 drwxr-xr-x 2 tomas tomas 16384 Jan 1 1970 . drwxr-xr-x 23 root root 4096 Feb 23 12:42 .. Totally empty... Conversely, the directory you mount things on doesn't have to be empty: its contents is just shadowed while the mount lasts. Cheers - -- tomás -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlqn1wQACgkQBcgs9XrR2kZE2QCfeYUbeissCPgETJSIu/LGKLM+ sMEAniUti1S3RLk6lfIhhrb7fUY5damO =uJRD -END PGP SIGNATURE-
Re: quick scripting 'is /P/Q mounted'
On Tue, Mar 13, 2018 at 08:49:58PM +1100, David wrote: > On 13 March 2018 at 14:40, Mike McClainwrote: > > > > If my other computer is South40 and I want to mount South40's /docs > > on my /south40/docs/ directory I can do that. As one script calls > > another I want to know if I need to mount South40 without > > $( mount | grep 'south40/docs'). > > > > Suggestions? > > Installing the package util-linux will provide the mountpoint command > which exits true=0 if its argument is in use as a mountpoint. Example: > > $ if mountpoint / ; then echo "exit status is $?" ; fi > / is a mountpoint > exit status is 0 > Unless I've misunderstood the question, you can tell if something is mounted at a mount point by checking if anything is present under the mount point, eg if you know there is a directory /Y that gets mounted under mount point /X, you can can make sure /X/Y doesn't exist under the mount poiunt and then check for the existence of /X/Y -- it will be there if the mount point is in use and not if not. Mark
Re: quick scripting 'is /P/Q mounted'
On 13 March 2018 at 14:40, Mike McClainwrote: > > If my other computer is South40 and I want to mount South40's /docs > on my /south40/docs/ directory I can do that. As one script calls > another I want to know if I need to mount South40 without > $( mount | grep 'south40/docs'). > > Suggestions? Installing the package util-linux will provide the mountpoint command which exits true=0 if its argument is in use as a mountpoint. Example: $ if mountpoint / ; then echo "exit status is $?" ; fi / is a mountpoint exit status is 0
Re: quick scripting 'is /P/Q mounted'
On 13/03/18 16:40, Mike McClain wrote: > A while back, Pierre Gaston posted this little tidbit to quickly > determine if my network is up: > [ "$( > Now I wonder if there is a similar file in /sys that would tell if > anything is mounted on a particular directory. I've browsed /sys but > not found what I'm looking for. > > If my other computer is South40 and I want to mount South40's /docs > on my /south40/docs/ directory I can do that. As one script calls > another I want to know if I need to mount South40 without > $( mount | grep 'south40/docs'). You could look at /proc/mounts, but that's similar to the output of mount. Or if it's for a specific directory, and you can put something in it, you can test for the existence of a special file in the directory. Something like [ -f /south40/docs/.flag ] Richard signature.asc Description: OpenPGP digital signature
quick scripting 'is /P/Q mounted'
A while back, Pierre Gaston posted this little tidbit to quickly determine if my network is up: [ "$(