[Tutor] Test If File System is mounted in Linux

Bill Campbell bill at celestial.net
Fri Mar 17 19:06:58 CET 2006


On Fri, Mar 17, 2006, Adam wrote:
>On 17/03/06, Bill Campbell <bill at celestial.net> wrote:
>> On Fri, Mar 17, 2006, Michael Lange wrote:
>> >On Fri, 17 Mar 2006 00:36:35 -0700
>> >fortezza-pyt <fortezza-pyt at fortezzazone.org> wrote:
>> >
>> >> If there a semi-standard way to test if a file system has been mounted
>> >> or not using Python? In the Linux command line, I can type "mount" and
>> >> see all mounted file system, and then see if the one I am looking for is
>> >> in the list. While I could replicate this with
>> >> Python, I am curious if there is an easier way.
>> >>
>> >
>> >Hi Fortezza,
>> >
>> >try os.path.ismount() .
>>
>> That's fine if one knows what the mount points are.
>>
>> The more general problem is to get a list of mounted file systems.
>>
>How about just reading the mtab? That's usually /etc/mtab it should be
>readable as a user and it means you don't have to rely on any other
>programs.

The words usually, and should are the kickers.  In the 24 years I've been
making my living on various versions of Unix type systems, I've seen a lot
of cases where this type of assumption either fails totally or gets me in
trouble because the vendor didn't do it the way they should.

This is the reason I started building standard open source tools for all
the systems we support (Richard Stallman would probably have said I was
creating GNU/Xenix and GNU/OpenServer systems back when we supported many
SCO systems :-).  My fingers automatically type gfind, gdu, etc., even on
Linux systems where I make symbolic links as necessary so I don't have to
remember what type of system I'm typing on.

One of the basic tenets of the *nix philosophy is ``build on the work of
others'', and it's a lot easier to leave figuring out the guts of various
systems to the authors of the gnu fileutils than it is to reinvent their
work every time I want to do something.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

A fake fortuneteller can be tolerated.  But an authentic soothsayer should
be shot on sight.  Cassandra did not get half the kicking around she deserved.
		-- R.A. Heinlein


More information about the Tutor mailing list