Search code examples
pythonlinuxscriptingmount

How to mount a network directory using python?


I need to mount a directory "dir" on a network machine "data" using python on a linux machine

I know that I can send the command via command line:

mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir

but how would I send those commands from a python script?


Solution

  • Here is one way:

    import os
    
    os.cmd ("mkdir ~/mnt/data_dir mount -t data:/dir/ /mnt/data_dir")
    

    You can also use "popen" if you want to read the output of the command in your script.

    HIH

    ...richie